Struct obstack::Obstack [] [src]

pub struct Obstack { /* fields omitted */ }

An obstack

Methods

impl Obstack
[src]

[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.

[src]

Constructs a new Obstack.

The initial capacity will be set to DEFAULT_INITIAL_CAPACITY.

[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!");

[src]

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]);

[src]

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][..]);

[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

impl Debug for Obstack
[src]

[src]

Formats the value using the given formatter.

impl Display for Obstack
[src]

[src]

Formats the value using the given formatter. Read more