[−][src]Struct obstack::Ref
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]
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> 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]
impl<'a, T> Debug for Ref<'a, T> where
T: Debug,
[src]
T: Debug,
impl<'a, T> Deref for Ref<'a, T>
[src]
impl<'a, T> DerefMut for Ref<'a, T>
[src]
impl<'a, T> Display for Ref<'a, T> where
T: Display,
[src]
T: Display,
impl<'a, T: ?Sized> Drop for Ref<'a, T>
[src]
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]
#[must_use]fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn clamp(self, min: Self, max: Self) -> Self
[src]
impl<'a, T> PartialEq<Ref<'a, T>> for Ref<'a, T> where
T: PartialEq<T>,
[src]
T: PartialEq<T>,
impl<'a, T> PartialOrd<Ref<'a, T>> for Ref<'a, T> where
T: PartialOrd,
[src]
T: PartialOrd,
fn partial_cmp(&self, other: &Ref<'a, T>) -> Option<Ordering>
[src]
fn le(&self, other: &Ref<'a, T>) -> bool
[src]
fn lt(&self, other: &Ref<'a, T>) -> bool
[src]
fn gt(&self, other: &Ref<'a, T>) -> bool
[src]
fn ge(&self, other: &Ref<'a, T>) -> bool
[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,
T: RefUnwindSafe,
impl<'a, T: ?Sized> Send for Ref<'a, T> where
T: Send,
T: Send,
impl<'a, T: ?Sized> Sync for Ref<'a, T> where
T: Sync,
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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,