Struct obstack::Ref [] [src]

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.

Methods

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

[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> Deref for Ref<'a, T>
[src]

The resulting type after dereferencing.

[src]

Dereferences the value.

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

[src]

Mutably dereferences the value.

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

[src]

Formats the value using the given formatter.

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

[src]

Formats the value using the given formatter.

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

[src]

Formats the value using the given formatter. Read more

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

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

[src]

This method tests for !=.

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

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

[src]

This method returns an Ordering between self and other. Read more

[src]

🔬 This is a nightly-only experimental API. (ord_max_min)

Compares and returns the maximum of two values. Read more

[src]

🔬 This is a nightly-only experimental API. (ord_max_min)

Compares and returns the minimum of two values. Read more

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

[src]

This method returns an ordering between self and other values if one exists. Read more

[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

[src]

This method tests less than (for self and other) and is used by the < operator. Read more

[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

[src]

Performs the conversion.

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

[src]

Performs the conversion.

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

[src]

Immutably borrows from an owned value. Read more

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

[src]

Mutably borrows from an owned value. Read more

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

[src]

Executes the destructor for this type. Read more