[][src]Struct obstack::Ref

pub struct Ref<'a, T: 'a + ?Sized> { /* fields omitted */ }

A wrapper referencing a value in an Obstack.

A Ref value owns the value it references, and will invoke drop on the value when the Ref goes out of scope. Effectively a Ref is a Box that uses an Obstack rather than the heap.

The inherent methods of Ref are all associated functions, which means you have to call them as e.g. Ref::unwrap(value) instead of value.unwrap(). This avoids conflicts with methods of the inner type T.

Implementations

impl<'a, T: ?Sized> Ref<'a, T>[src]

pub fn unwrap(this: Self) -> T where
    T: Sized
[src]

Returns the owned value, consuming the Ref.

This allows the value to taken out of the Obstack and used even after it goes out of scope:

fn f() -> String {
    let stack = Obstack::new();
    let r = stack.push(String::from("foo"));

    Ref::unwrap(r)
}

assert_eq!(f(), "foo");

Since obstacks only free memory when they go out of scope, the bytes_used remains unchanged:

let r = stack.push(String::new());

let used = stack.bytes_used();
let inner = Ref::unwrap(r);

assert_eq!(used, stack.bytes_used());

Trait Implementations

impl<'a, T> AsMut<T> for Ref<'a, T>[src]

impl<'a, T> AsRef<T> for Ref<'a, T>[src]

impl<'a, T> Borrow<T> for Ref<'a, T>[src]

impl<'a, T> BorrowMut<T> for Ref<'a, T>[src]

impl<'a, T> Debug for Ref<'a, T> where
    T: Debug
[src]

impl<'a, T> Deref for Ref<'a, T>[src]

type Target = T

The resulting type after dereferencing.

impl<'a, T> DerefMut for Ref<'a, T>[src]

impl<'a, T> Display for Ref<'a, T> where
    T: Display
[src]

impl<'a, T: ?Sized> Drop for Ref<'a, T>[src]

impl<'a, T> Eq for Ref<'a, T> where
    T: Eq
[src]

impl<'a, T> Ord for Ref<'a, T> where
    T: Ord
[src]

impl<'a, T> PartialEq<Ref<'a, T>> for Ref<'a, T> where
    T: PartialEq<T>, 
[src]

impl<'a, T> PartialOrd<Ref<'a, T>> for Ref<'a, T> where
    T: PartialOrd
[src]

impl<'a, T> Pointer for Ref<'a, T>[src]

Auto Trait Implementations

impl<'a, T: ?Sized> RefUnwindSafe for Ref<'a, T> where
    T: RefUnwindSafe

impl<'a, T: ?Sized> Send for Ref<'a, T> where
    T: Send

impl<'a, T: ?Sized> Sync for Ref<'a, T> where
    T: Sync

impl<'a, T: ?Sized> Unpin for Ref<'a, T>

impl<'a, T> !UnwindSafe for Ref<'a, T>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.