Trait supercow::ext::SafeBorrow [] [src]

pub unsafe trait SafeBorrow<T: ?Sized>: Borrow<T> {
    fn borrow_replacement<'a>(ptr: &'a T) -> &'a T;
}

Extension of Borrow used to allow Supercow::to_mut() to work safely.

Unsafety

Behaviour is undefined if the borrow() implementation may return a reference into self which is more than MAX_INTERNAL_BORROW_DISPLACEMENT bytes beyond the base of self.

Required Methods

Given ptr, which was obtained from a prior call to Self::borrow(), return a value with the same nominal lifetime which is guaranteed to survive mutations to Self.

Types which implement Borrow by pure, constant pointer arithmetic on self can simply return ptr unmodified. Other types typically need to provide some static reference, such as the empty string for &str.

Unsafety

Behaviour is undefined if this call returns ptr, but a mutation to Self could invalidate the reference.

Implementors