rebind

Function rebind 

Source
pub unsafe fn rebind<'r, T>(v: T) -> T::Rebound
where T: Bound<'r>,
Expand description

Rebinds a value to a arbitray lifetime.

§Safety

This method is wildly unsafe if not used correctly. Rebinding is essentially a somewhat more restrictive std::mem::transmute and should be treated as such.

In the context of the dreck crate, rebind can be used to change the 'gc lifetime of a object to some other 'gc lifetime; either the lifetime of an other gc’d object or a Root borrow.

Rebinding to a borrowed Root of the same 'own lifetime is always safe to do as holding onto an root borrow prevents one from running garbage collection. One should always prefer the safe rebind! macro for rebinding a value to a Root borrow.

It is also safe to rebind a object to the lifetime of a root::RootGuard which created with the same object if one ensures that Root::root_gc is called correctly. One should always prefer the safe root! macro for rooting a gc’d object.

The final safe thing to do with this function and its only use case is to implement traced collections. If a collection is traced it is safe to rebind objects which are to be contained to the 'gc lifetime of the collection.

§Panics

This function will panic if the Bound trait is implemented in correctly and T and T::Rebound have different sizes.