You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
FIX: Only reference types, not Box types, can have a lifetime annotation; specifically, only &'a T or &'a mut T are allowed.
storage vs. value
storage has a mutability flag
A storage of type T contains and owns a value of type T in it
A value can own a storage
(v: Box<T>) refers to and owns a storage of type T
A value can borrow a storage with or without mutability
(v: &T) refers to and reads from a storage of type T
(v: &mut T) refers to and reads from / writes to a storage of type T
Lifetime analysis: static vs. dynamic (RC or ARC)
A borrowed reference should not live longer than the owner.
Sharing XOR Mutation analysis: static vs. dynamic (Refcell or Mutex)
Sharing and mutation to a storage cannot happen at the same time.
Unsized (or Dynamically-Sized) types
Struct (field access)
Enum (pattern match)
Generic Types are monomorphized since the size of varies for each T.
"impl TR" returns a concrete type implementing the trait TR but hides the type information from the programmer.
Lifetime annotation <'a> only comes with reference (ie, borrowed) types (&'a T or &'a mut T) but NOT Box types (Box<T>).
This is because the lifetimes of borrowed types are determined by their owners
while the lifetimes of all the other types including box types are determined by myself (ie, not shared with others).
The interpretation of lifetime annotations depends on what are input references and what are output references.
Every lifetime consistent with the input references should be consistent with the output references.
The text was updated successfully, but these errors were encountered:
FIX: Only reference types, not Box types, can have a lifetime annotation; specifically, only
&'a T
or&'a mut T
are allowed.(v: Box<T>)
refers to and owns a storage of type T(v: &T)
refers to and reads from a storage of type T(v: &mut T)
refers to and reads from / writes to a storage of type T&'a T
or&'a mut T
) but NOT Box types (Box<T>
).while the lifetimes of all the other types including box types are determined by myself (ie, not shared with others).
The text was updated successfully, but these errors were encountered: