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]
fn unwrap(this: Self) -> T where
T: Sized, [src]
T: Sized,
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]
type Target = T
The resulting type after dereferencing.
fn deref(&self) -> &T[src]
Dereferences the value.
impl<'a, T> DerefMut for Ref<'a, T>[src]
impl<'a, T> Pointer for Ref<'a, T>[src]
fn fmt(&self, f: &mut Formatter) -> Result<(), Error>[src]
Formats the value using the given formatter.
impl<'a, T> Debug for Ref<'a, T> where
T: Debug, [src]
T: Debug,
fn fmt(&self, f: &mut Formatter) -> Result<(), Error>[src]
Formats the value using the given formatter.
impl<'a, T> Display for Ref<'a, T> where
T: Display, [src]
T: Display,
fn fmt(&self, f: &mut Formatter) -> Result<(), Error>[src]
Formats the value using the given formatter. Read more
impl<'a, T> PartialEq for Ref<'a, T> where
T: PartialEq<T>, [src]
T: PartialEq<T>,
fn eq(&self, other: &Ref<'a, T>) -> bool[src]
This method tests for self and other values to be equal, and is used by ==. Read more
fn ne(&self, other: &Ref<'a, T>) -> bool[src]
This method tests for !=.
impl<'a, T> Eq for Ref<'a, T> where
T: Eq, [src]
T: Eq,
impl<'a, T> Ord for Ref<'a, T> where
T: Ord, [src]
T: Ord,
fn cmp(&self, other: &Ref<'a, T>) -> Ordering[src]
This method returns an Ordering between self and other. Read more
fn max(self, other: Self) -> Self[src]
ord_max_min)Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self[src]
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]
T: PartialOrd,
fn partial_cmp(&self, other: &Ref<'a, T>) -> Option<Ordering>[src]
This method returns an ordering between self and other values if one exists. Read more
fn le(&self, other: &Ref<'a, T>) -> bool[src]
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
fn lt(&self, other: &Ref<'a, T>) -> bool[src]
This method tests less than (for self and other) and is used by the < operator. Read more
fn gt(&self, other: &Ref<'a, T>) -> bool[src]
This method tests greater than (for self and other) and is used by the > operator. Read more
fn ge(&self, other: &Ref<'a, T>) -> bool[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]
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]
fn borrow_mut(&mut self) -> &mut T[src]
Mutably borrows from an owned value. Read more