InplaceBox

Struct InplaceBox 

Source
pub struct InplaceBox<T: ?Sized, const SIZE: usize> { /* private fields */ }
Expand description

A container similar to Box, but without heap allocation.

It stores data inline within a fixed-size buffer.

Implementations§

Source§

impl<T: ?Sized, const SIZE: usize> InplaceBox<T, SIZE>

Source

pub fn new<'a, U: Sized + Unsize<T> + 'a>(value: U) -> Self

Construct a new object in-place in this object.

The type of the value must be convertible to dyn T and its size and alignment less than or equal to that of the InplaceBox space for the object.

Type match, size and alignment are checked statically by the compiler.

Source§

impl<T: ?Sized, const SIZE: usize> InplaceBox<T, SIZE>

Source

pub unsafe fn new_unchecked<'a, U: Sized + Unsize<T> + 'a>(value: U) -> Self

Construct a new object in-place in this object, without checking the size.

The type of the value must be convertible to dyn T.

This constructor is provided to allow constructing objects either in InplaceBox of a certain size or on heap for larger sizes. Since if conditions in the caller on the object size are not optimized out in debug mode, the code wouldn’t compile when statically checking the size. With unchecked version, it’s possible to have such dynamically-switched generics.

§Safety

The caller needs to ensure that the size of the type U is less than or equal to the SIZE of the InplaceBox. Only the type match and alignment is checked statically by the compiler.

Prefer to use the safe Self::new constructor which checks for the size.

Trait Implementations§

Source§

impl<T: ?Sized, const SIZE: usize> AsMut<T> for InplaceBox<T, SIZE>

Source§

fn as_mut(&mut self) -> &mut T

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<T: ?Sized, const SIZE: usize> AsRef<T> for InplaceBox<T, SIZE>

Source§

fn as_ref(&self) -> &T

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T: ?Sized, const SIZE: usize> Borrow<T> for InplaceBox<T, SIZE>

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T: ?Sized, const SIZE: usize> BorrowMut<T> for InplaceBox<T, SIZE>

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T: ?Sized + Debug, const SIZE: usize> Debug for InplaceBox<T, SIZE>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: ?Sized, const SIZE: usize> Deref for InplaceBox<T, SIZE>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<T: ?Sized, const SIZE: usize> DerefMut for InplaceBox<T, SIZE>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<T: ?Sized + Display, const SIZE: usize> Display for InplaceBox<T, SIZE>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: ?Sized, const SIZE: usize> Drop for InplaceBox<T, SIZE>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<Args: Tuple, F: Fn<Args> + ?Sized, const SIZE: usize> Fn<Args> for InplaceBox<F, SIZE>

Source§

extern "rust-call" fn call(&self, args: Args) -> Self::Output

🔬This is a nightly-only experimental API. (fn_traits)
Performs the call operation.
Source§

impl<Args: Tuple, F: FnMut<Args> + ?Sized, const SIZE: usize> FnMut<Args> for InplaceBox<F, SIZE>

Source§

extern "rust-call" fn call_mut(&mut self, args: Args) -> Self::Output

🔬This is a nightly-only experimental API. (fn_traits)
Performs the call operation.
Source§

impl<Args: Tuple, F: FnOnce<Args> + ?Sized, const SIZE: usize> FnOnce<Args> for InplaceBox<F, SIZE>

Source§

type Output = <F as FnOnce<Args>>::Output

The returned type after the call operator is used.
Source§

extern "rust-call" fn call_once(self, args: Args) -> Self::Output

🔬This is a nightly-only experimental API. (fn_traits)
Performs the call operation.
Source§

impl<T: ?Sized + Future, const SIZE: usize> Future for InplaceBox<T, SIZE>

Source§

type Output = <T as Future>::Output

The type of value produced on completion.
Source§

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output>

Attempts to resolve the future to a final value, registering the current task for wakeup if the value is not yet available. Read more
Source§

impl<T: ?Sized, const SIZE: usize> Pointer for InplaceBox<T, SIZE>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T, const SIZE: usize> Freeze for InplaceBox<T, SIZE>
where T: ?Sized,

§

impl<T, const SIZE: usize> RefUnwindSafe for InplaceBox<T, SIZE>
where T: RefUnwindSafe + ?Sized,

§

impl<T, const SIZE: usize> Send for InplaceBox<T, SIZE>
where T: Send + ?Sized,

§

impl<T, const SIZE: usize> Sync for InplaceBox<T, SIZE>
where T: Sync + ?Sized,

§

impl<T, const SIZE: usize> Unpin for InplaceBox<T, SIZE>
where T: Unpin + ?Sized,

§

impl<T, const SIZE: usize> UnwindSafe for InplaceBox<T, SIZE>
where T: UnwindSafe + ?Sized,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<F> IntoFuture for F
where F: Future,

Source§

type Output = <F as Future>::Output

The output that the future will produce on completion.
Source§

type IntoFuture = F

Which kind of future are we turning this into?
Source§

fn into_future(self) -> <F as IntoFuture>::IntoFuture

Creates a future from a value. Read more
Source§

impl<F> Pattern for F
where F: FnMut(char) -> bool,

Source§

type Searcher<'a> = CharPredicateSearcher<'a, F>

🔬This is a nightly-only experimental API. (pattern)
Associated searcher for this pattern
Source§

fn into_searcher<'a>(self, haystack: &'a str) -> CharPredicateSearcher<'a, F>

🔬This is a nightly-only experimental API. (pattern)
Constructs the associated searcher from self and the haystack to search in.
Source§

fn is_contained_in<'a>(self, haystack: &'a str) -> bool

🔬This is a nightly-only experimental API. (pattern)
Checks whether the pattern matches anywhere in the haystack
Source§

fn is_prefix_of<'a>(self, haystack: &'a str) -> bool

🔬This is a nightly-only experimental API. (pattern)
Checks whether the pattern matches at the front of the haystack
Source§

fn strip_prefix_of<'a>(self, haystack: &'a str) -> Option<&'a str>

🔬This is a nightly-only experimental API. (pattern)
Removes the pattern from the front of haystack, if it matches.
Source§

fn is_suffix_of<'a>(self, haystack: &'a str) -> bool

🔬This is a nightly-only experimental API. (pattern)
Checks whether the pattern matches at the back of the haystack
Source§

fn strip_suffix_of<'a>(self, haystack: &'a str) -> Option<&'a str>

🔬This is a nightly-only experimental API. (pattern)
Removes the pattern from the back of haystack, if it matches.
Source§

fn as_utf8_pattern(&self) -> Option<Utf8Pattern<'_>>

🔬This is a nightly-only experimental API. (pattern)
Returns the pattern as utf-8 bytes if possible.
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.