snippet rust programming

Notes I took while going through this excellent video: https://youtu.be/xcygqF5LVmM

An obect whose only property is that it represents a Trait

My struct is Size-able if all its fields are Size-able. You don't implement yourself manually

A bare Trait is not Sized

There's no major pros or cons but:

I have something like:

fn myfunction(arg: Box<dyn SayHello>) {
  arg.hello();
}

For more, see https://doc.rust-lang.org/book/ch19-04-advanced-types.html

Answers the question:

How does myfunction know where to find the hello method for all these
types that implement SayHello?

&str -> &dyn Hei

The trait object stores:

  1. Pointer to the str
  2. A reference to the vtable
       &HeiVtable {
            hei: &<str as Hei>::hei
        }
    

So, what if I want to have a trait object to a type that implements both Hello and AsRef?