pub struct Ref<T> { /* private fields */ }Expand description
Wrapper for a raw pointer which lets us treat it like a reference.
You are strongly discouraged from exposing this type directly in your data structures. This type is essentially a giant footgun. In particular:
-
No safety checks or lifetimes protect this reference, so a
Ref<T>may be invalidated without warning. (You may use aRef<T>safely by ensuring that the references passed toRef<T>::new()will never be dropped before the wrappers. A good example of when you’d be able to do this is in in a struct that hasRef<T>references into a data structure that it also owns.) -
The impls for
Debug,Eq,Hash,Ord,PartialEq, andPartialOrdall dereference the raw pointer that this structure wraps. As a result, aRef<T>must be removed from any data structures that make use of any of those interfaces before it is invalidated. -
Ref<T>wraps a value of type*const T, which is not usuallySendorSync. This restriction is overridden for aRef<T>wrapper so that data structures which encapsulate it may themselves beSendorSync. This makes it the responsibility of data structures using such wrappers to satisfy the contracts of those types.