[][src]Struct owned_alloc::RawVec

pub struct RawVec<T> { /* fields omitted */ }

Raw Vector allocation. This allocation, instead of holding a pointer to a single T, holds a pointer to as many T are required. The allocation is resizable and is freed on drop. No initialization or deinitialization of the elements is performed. This type may be useful for Vec-like types. If the size of the allocation is zero, no allocation is performed and a dangling pointer is used (just like in std). For the drop checker, the type acts as if it contains a T due to usage of PhantomData<T>.

extern crate owned_alloc;

use owned_alloc::RawVec;

let mut vec = RawVec::<usize>::with_capacity(200);
assert_eq!(200, vec.cap());
assert_eq!(200, unsafe { vec.as_slice().len() });

vec.resize(354);
assert_eq!(354, vec.cap());
assert_eq!(354, unsafe { vec.as_slice().len() });

Methods

impl<T> RawVec<T>
[src]

Creates a new RawVec of capacity 0 and a dangling pointer. No allocation is performed.

Creates a new RawVec with a given capacity. In case of allocation error, the handler registered via stdlib is called. In case of overflow calculating the total size, the function panics.

Creates a new RawVec with a given capacity. In case of allocation error or overflow calculating the total size, Err is returned.

Creates a RawVec from a plain old standard library Vec. Beware, only the pointer and the capacity are saved. The length is discarded. If you want to keep track of the length, you will have to store it for yourself. Note also that no element is dropped (ever) by the RawVec.

Safety

This function is unsafe because there are no guarantees that Vec and RawVec allocate in the same way. They probably do in the Rust version you are using, but there are no future guarantees.

Recreate the RawVec from a raw non-null pointer and a capacity.

Safety

This functions is unsafe because passing the wrong pointer leads to undefined behaviour. Passing wrong capacity also leads to undefined behaviour.

Recreate the RawVec from a raw non-null pointer to a slice with length equal to the RawVec's capacity.

Safety

This functions is unsafe because passing the wrong pointer leads to undefined behaviour, including passing a pointer with the wrong length.

The requested allocation capacity. It is guaranteed to be the capacity passed to the last capacity-modifier method. Those are with_capacity, try_with_capacity and resize. The methods new and try_new initialize the capacity to 0.

The raw non-null pointer to the first element.

The raw non-null pointer to the slice with length equal to the RawVec's capacity.

"Forgets" dropping the allocation and returns a raw non-null pointer to the slice with length equal to the RawVec's capacity.

Encodes the RawVec as an immutable reference to a slice with length equal to the capacity.

Safety

This function is unsafe because if the index of an uninitialized element is accessed incorrectly, undefined behavior occurs.

Encodes the RawVec as an mutable reference to a slice with length equal to the capacity.

Safety

This function is unsafe because if the index of an uninitialized element is accessed incorrectly, undefined behavior occurs.

Creates a plain old standard library Vec from the RawVec and a given length.

Safety

This function is unsafe because there are no guarantees that Vec and RawVec allocate in the same way. They probably do in the Rust version you are using, but there are no future guarantees. Also, the length argument must be passed correctly, since the elements until the given length will be considered correctly, but the RawVec initialize no element.

Resizes the RawVec with a given capacity. In case of allocation error, the handler registered via stdlib is called. In case of overflow calculating the total size, the function panics.

Resizes the RawVec with a given capacity. In case of allocation error or overflow calculating the total size, Err is returned. In case of failure, the original allocation is untouched.

Trait Implementations

impl<T> Sync for RawVec<T> where
    T: Sync
[src]

impl<T> From<RawVec<T>> for UninitAlloc<[T]>
[src]

impl<T> From<UninitAlloc<T>> for RawVec<T>
[src]

impl<T> Send for RawVec<T> where
    T: Send
[src]

impl<T> Drop for RawVec<T>
[src]

impl<T> Debug for RawVec<T>
[src]

Blanket Implementations

impl<T> From for T
[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> BorrowMut for T where
    T: ?Sized
[src]