1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//! Unsafe traits and functions cautiously used in the library but made unsafe to discourage their external use.

/// This is required to generalize TreeIterator with a single ::new method.
pub unsafe trait UnsafeClone {
    /// Clones the object.
    unsafe fn unsafe_clone(&self) -> Self;
}

/// This is required to generalize TreeIterator with a single ::new method.
pub unsafe trait UnsafeBorrow<'a> {
    /// The type of the borrowed object.
    type Borrow;
    /// Borrows the object.
    unsafe fn borrow(&'a self) -> Self::Borrow;
}

// TODO: Write about cases where this is needed.
/// Makes the reference live longer.
#[inline]
pub unsafe fn longer_ref<'longer, T>(t: &T) -> &'longer T { unsafe { &*(t as *const T) } }

/// Makes the mutable reference live longer.
#[inline]
pub unsafe fn longer_mut<'longer, T>(t: &mut T) -> &'longer mut T { unsafe { &mut *(t as *mut T) } }