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
fn borrow_replacement<'a>(ptr: &'a T) -> &'a T
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
impl<T: ?Sized> SafeBorrow<T> for T
impl<B, T> SafeBorrow<[B]> for T where T: Borrow<[B]>
impl<T> SafeBorrow<str> for T where T: Borrow<str>
impl<T> SafeBorrow<CStr> for T where T: Borrow<CStr>
impl<T> SafeBorrow<OsStr> for T where T: Borrow<OsStr>
impl<T> SafeBorrow<Path> for T where T: Borrow<Path>