pub struct OwnedVal<T: DropRaw + ?Sized, A: Allocator = Global> { /* private fields */ }
Expand description

A pointer type for memory allocation.

Implementations

Returns a reference to the underlying allocator.

Note: this is an associated function, which means that you have to call it as OwnedVal::allocator(&v) instead of owned_val.allocator(). This is so that there is no conflict with a method on the inner type.

Constructs an owned Val from a raw pointer in the given allocator.

After calling this function, the raw pointer is owned by the resulting OwnedVal. Specifically, the OwnedVal destructor will call the DropRaw destructor of T and free the allocated memory. For this to be safe, the memory must have been allocated in accordance with the memory layout used by OwnedVal.

Safety
  • ptr must point to a memory block currently allocated by alloc.
  • The layout used to allocate ptr must exactly match the return value of Layout::for_value.
  • ptr must point to an initialized T.

Constructs an owned Val from an initialized Frame.

Safety

frame must be initialized.

Consumes the OwnedVal, returning a wrapped raw pointer and the allocator.

The pointer will be properly aligned and non-null.

After calling this function, the caller is responsible for the memory previously managed by the OwnedVal. In particular, the caller should properly destroy T with DropRaw and release the memory, taking into account the memory layout used by OwnedVal. The easiest way to do this is to convert the raw pointer back into an OwnedVal with the OwnedVal::from_raw_in function, allowing the OwnedVal destructor to perform the cleanup.

Note: this is an associated function, which means that you have to call it as OwnedVal::into_raw(b) instead of b.into_raw(). This is so that there is no conflict with a method on the inner type.

Returns a Ref of the owned value.

Returns a Mut of the owned value.

Allocates memory in the given allocator then places x into it.

Allocates memory in the Global allocator and then places x into it.

Trait Implementations

Formats the value using the given formatter. Read more
The resulting type after dereferencing.
Dereferences the value.
Mutably dereferences the value.
Formats the value using the given formatter. Read more
Executes the destructor for this type. Read more
The target value of this type.
Returns a pointer to this type’s target.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Formats the value using the given formatter.
Formats the value using the given formatter.

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type for metadata in pointers and references to Self.
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.