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>
impl<T: ?Sized, const SIZE: usize> InplaceBox<T, SIZE>
Sourcepub fn new<'a, U: Sized + Unsize<T> + 'a>(value: U) -> Self
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>
impl<T: ?Sized, const SIZE: usize> InplaceBox<T, SIZE>
Sourcepub unsafe fn new_unchecked<'a, U: Sized + Unsize<T> + 'a>(value: U) -> Self
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> BorrowMut<T> for InplaceBox<T, SIZE>
impl<T: ?Sized, const SIZE: usize> BorrowMut<T> for InplaceBox<T, SIZE>
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<Args: Tuple, F: FnMut<Args> + ?Sized, const SIZE: usize> FnMut<Args> for InplaceBox<F, SIZE>
impl<Args: Tuple, F: FnMut<Args> + ?Sized, const SIZE: usize> FnMut<Args> for InplaceBox<F, SIZE>
Source§impl<Args: Tuple, F: FnOnce<Args> + ?Sized, const SIZE: usize> FnOnce<Args> for InplaceBox<F, SIZE>
impl<Args: Tuple, F: FnOnce<Args> + ?Sized, const SIZE: usize> FnOnce<Args> for InplaceBox<F, SIZE>
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>
impl<T, const SIZE: usize> Sync for InplaceBox<T, SIZE>
impl<T, const SIZE: usize> Unpin for InplaceBox<T, SIZE>
impl<T, const SIZE: usize> UnwindSafe for InplaceBox<T, SIZE>where
T: UnwindSafe + ?Sized,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<F> IntoFuture for Fwhere
F: Future,
impl<F> IntoFuture for Fwhere
F: Future,
Source§type IntoFuture = F
type IntoFuture = F
Source§fn into_future(self) -> <F as IntoFuture>::IntoFuture
fn into_future(self) -> <F as IntoFuture>::IntoFuture
Source§impl<F> Pattern for F
impl<F> Pattern for F
Source§type Searcher<'a> = CharPredicateSearcher<'a, F>
type Searcher<'a> = CharPredicateSearcher<'a, F>
pattern)Source§fn into_searcher<'a>(self, haystack: &'a str) -> CharPredicateSearcher<'a, F>
fn into_searcher<'a>(self, haystack: &'a str) -> CharPredicateSearcher<'a, F>
pattern)self and the haystack to search in.Source§fn is_contained_in<'a>(self, haystack: &'a str) -> bool
fn is_contained_in<'a>(self, haystack: &'a str) -> bool
pattern)Source§fn is_prefix_of<'a>(self, haystack: &'a str) -> bool
fn is_prefix_of<'a>(self, haystack: &'a str) -> bool
pattern)Source§fn strip_prefix_of<'a>(self, haystack: &'a str) -> Option<&'a str>
fn strip_prefix_of<'a>(self, haystack: &'a str) -> Option<&'a str>
pattern)Source§fn is_suffix_of<'a>(self, haystack: &'a str) -> boolwhere
CharPredicateSearcher<'a, F>: ReverseSearcher<'a>,
fn is_suffix_of<'a>(self, haystack: &'a str) -> boolwhere
CharPredicateSearcher<'a, F>: ReverseSearcher<'a>,
pattern)Source§fn strip_suffix_of<'a>(self, haystack: &'a str) -> Option<&'a str>where
CharPredicateSearcher<'a, F>: ReverseSearcher<'a>,
fn strip_suffix_of<'a>(self, haystack: &'a str) -> Option<&'a str>where
CharPredicateSearcher<'a, F>: ReverseSearcher<'a>,
pattern)Source§fn as_utf8_pattern(&self) -> Option<Utf8Pattern<'_>>
fn as_utf8_pattern(&self) -> Option<Utf8Pattern<'_>>
pattern)