[−][src]Struct obstack::Obstack
An obstack
Implementations
impl Obstack
[src]
pub fn with_initial_capacity(initial_capacity: usize) -> Self
[src]
Constructs a new Obstack
with the specified initial capacity.
The obstack will be able to allocate at least initial_capacity
bytes before having to
allocate again.
pub fn new() -> Self
[src]
Constructs a new Obstack
.
The initial capacity will be set to DEFAULT_INITIAL_CAPACITY
.
pub fn push<'a, T>(&'a self, value: T) -> Ref<'a, T>
[src]
Pushes a value to the Obstack
.
Returns a Ref
that can be dereferenced to the value's location on the stack.
let r: Ref<String> = stack.push(String::from("Hello World!")); assert_eq!(*r, "Hello World!");
pub fn push_copy<'a, T>(&'a self, value: T) -> &'a mut T where
T: Copy,
[src]
T: Copy,
Pushes a Copy
value to the Obstack
.
Returns a mutable reference to the value on the stack.
let r: &mut [u8; 5] = stack.push_copy([1,2,3,4,5]); assert_eq!(*r, [1,2,3,4,5]);
pub fn copy_from_slice<'a, T>(&'a self, src: &[T]) -> &'a mut [T] where
T: Copy,
[src]
T: Copy,
Copies values from a slice to the Obstack
.
Returns a mutable reference to a newly allocated slice:
let v: Box<[u8]> = Box::new([1,2,3,4,5]); let r: &mut [u8] = stack.copy_from_slice(&v[0..3]); assert_eq!(r.len(), 3); assert_eq!(r, &[1,2,3][..]);
Zero-length slices work as expected without allocations:
let prev_used = stack.bytes_used(); let r: &mut [u8] = stack.copy_from_slice(&[]); assert_eq!(prev_used, stack.bytes_used()); assert_eq!(r.len(), 0); assert_eq!(r, &[]);
As do slices of zero-sized types:
let v: Box<[()]> = Box::new([(); 1_000]); let prev_used = stack.bytes_used(); let r: &mut [()] = stack.copy_from_slice(&v); assert_eq!(prev_used, stack.bytes_used()); assert_eq!(r.len(), 1_000); assert!(r == &[(); 1_000][..]);
pub fn bytes_used(&self) -> usize
[src]
Returns the total bytes currently used by values.
Includes bytes used for alignment padding. However, this figure is not the total size
allocated by the Obstack
, which would include bytes allocated for parts of segments
that haven't been used yet. Thus the return value of this method will change after every
non-zero-sized value allocated.
bytes_used
always starts at zero:
let stack = Obstack::new(); assert_eq!(stack.bytes_used(), 0);
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Obstack
impl Send for Obstack
impl !Sync for Obstack
impl Unpin for Obstack
impl UnwindSafe for Obstack
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>,