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() });
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
.
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.
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.
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.
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.
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.
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.
Executes the destructor for this type. Read more
Formats the value using the given formatter. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Mutably borrows from an owned value. Read more