Struct inline_dyn::InlineDyn[][src]

pub struct InlineDyn<'a, D: ?Sized + 'a, S: Size = DefaultSize, A: Align = S> { /* fields omitted */ }

A container type that stores a dynamically-sized type (e.g., a trait object) inline within the container.

The S and A generic parameters specify the size and alignment (in bytes) of the internal storage.

Examples

use inline_dyn::fmt::InlineDynDebug;

let val: InlineDynDebug = InlineDynDebug::try_new(42u8).unwrap();
assert_eq!(format!("{:?}", val), "42");

Implementations

impl<'a, D, S, A> InlineDyn<'a, D, S, A> where
    D: ?Sized,
    S: Size,
    A: Align
[src]

pub fn try_new<T>(value: T) -> Result<Self, T> where
    T: Unsize<D> + 'a, 
[src]

This is supported on crate feature nightly only.

Attempt to construct a new InlineDyn containing the given value.

The size and alignment of the internal storage must be large enough to store the given value, otherwise the value is returned.

Note: if not using the nightly feature, this method is only implemented for certain values of D. The inline_dyn! macro can be used as alternative on stable.

pub fn try_or_box<T>(value: T) -> Self where
    T: Unsize<D> + 'a,
    Box<T>: Unsize<D> + 'a,
    S: IsGreaterOrEqual<DefaultSize>,
    A: IsGreaterOrEqual<DefaultSize>, 
[src]

This is supported on crate features nightly and alloc only.

Construct a new InlineDyn containing the given value if the value can fit in the internal storage, or else box the value and store that.

Note: if not using the nightly feature, this method is only implemented for certain values of D. The inline_dyn_box! macro can be used as alternative on stable.

Examples

use core::mem;
use inline_dyn::fmt::InlineDynDebug;

#[derive(Debug)]
struct LargerThanBox([usize; 5]);

let val: InlineDynDebug = InlineDynDebug::try_or_box(LargerThanBox([1, 2, 3, 4, 5]));
assert!(mem::size_of_val(val.get_ref()) < mem::size_of::<LargerThanBox>());
assert_eq!(format!("{:?}", val.get_ref()), "LargerThanBox([1, 2, 3, 4, 5])");

impl<D: ?Sized, S, A> InlineDyn<'static, D, S, A> where
    D: Any,
    S: Size,
    A: Align
[src]

pub fn downcast<T: Any>(self) -> Result<T, Self>[src]

impl<'a, D: ?Sized, S: Size, A: Align> InlineDyn<'a, D, S, A>[src]

pub fn get_ref(&self) -> &D[src]

Returns a shared reference to the stored value.

pub fn get_mut(&mut self) -> &mut D[src]

Returns a mutable reference to the stored value.

pub fn grow<U, V>(this: Self) -> InlineDyn<'a, D, U, V>

Notable traits for InlineDyn<'_, I, S, A>

impl<I: ?Sized, S, A> Iterator for InlineDyn<'_, I, S, A> where
    I: Iterator,
    S: Size,
    A: Align
type Item = I::Item;impl<T: ?Sized, S, A> Read for InlineDyn<'_, T, S, A> where
    T: Read,
    S: Size,
    A: Align
impl<T: ?Sized, S, A> Write for InlineDyn<'_, T, S, A> where
    T: Write,
    S: Size,
    A: Align
impl<F: ?Sized, S, A> Future for InlineDyn<'_, F, S, A> where
    F: Future + Unpin,
    S: Size,
    A: Align
type Output = F::Output;
where
    U: Size + IsGreaterOrEqual<S>,
    V: Align + IsGreaterOrEqual<A>, 
[src]

Creates a new InlineDyn with a larger internal storage containing the value stored in this.

pub fn try_resize<U, V>(this: Self) -> Result<InlineDyn<'a, D, U, V>, Self> where
    U: Size,
    V: Align
[src]

Attempts to create a new InlineDyn with the given size and alignment for the internal storage containing the value stored in this.

The size and alignment must be large enough to store the contained value, otherwise this is returned.

Trait Implementations

impl<T: ?Sized, S, A> BufRead for InlineDyn<'_, T, S, A> where
    T: BufRead,
    S: Size,
    A: Align
[src]

This is supported on crate feature std only.

impl<D: Debug + ?Sized, S: Size, A: Align> Debug for InlineDyn<'_, D, S, A>[src]

impl<D: ?Sized, S: Size, A: Align> Deref for InlineDyn<'_, D, S, A>[src]

type Target = D

The resulting type after dereferencing.

impl<D: ?Sized, S: Size, A: Align> DerefMut for InlineDyn<'_, D, S, A>[src]

impl<D: Display + ?Sized, S: Size, A: Align> Display for InlineDyn<'_, D, S, A>[src]

impl<I: ?Sized, S, A> DoubleEndedIterator for InlineDyn<'_, I, S, A> where
    I: DoubleEndedIterator,
    S: Size,
    A: Align
[src]

impl<D: ?Sized, S: Size, A: Align> Drop for InlineDyn<'_, D, S, A>[src]

impl<E: ?Sized, S, A> Error for InlineDyn<'_, E, S, A> where
    E: Error,
    S: Size,
    A: Align
[src]

This is supported on crate feature std only.

impl<I: ?Sized, S, A> ExactSizeIterator for InlineDyn<'_, I, S, A> where
    I: ExactSizeIterator,
    S: Size,
    A: Align
[src]

impl<I: ?Sized, S, A> FusedIterator for InlineDyn<'_, I, S, A> where
    I: FusedIterator,
    S: Size,
    A: Align
[src]

impl<F: ?Sized, S, A> Future for InlineDyn<'_, F, S, A> where
    F: Future + Unpin,
    S: Size,
    A: Align
[src]

type Output = F::Output

The type of value produced on completion.

impl<I: ?Sized, S, A> Iterator for InlineDyn<'_, I, S, A> where
    I: Iterator,
    S: Size,
    A: Align
[src]

type Item = I::Item

The type of the elements being iterated over.

impl<T: ?Sized, S, A> Read for InlineDyn<'_, T, S, A> where
    T: Read,
    S: Size,
    A: Align
[src]

This is supported on crate feature std only.

impl<T: ?Sized, S, A> Seek for InlineDyn<'_, T, S, A> where
    T: Seek,
    S: Size,
    A: Align
[src]

This is supported on crate feature std only.

impl<T: ?Sized, S, A> Write for InlineDyn<'_, T, S, A> where
    T: Write,
    S: Size,
    A: Align
[src]

This is supported on crate feature std only.

Auto Trait Implementations

impl<'a, D: ?Sized, S, A> RefUnwindSafe for InlineDyn<'a, D, S, A> where
    D: RefUnwindSafe,
    <A as Align>::Output: RefUnwindSafe,
    <S as Size>::Output: RefUnwindSafe
[src]

impl<'a, D: ?Sized, S, A> Send for InlineDyn<'a, D, S, A> where
    D: Send
[src]

impl<'a, D: ?Sized, S, A> Sync for InlineDyn<'a, D, S, A> where
    D: Sync
[src]

impl<'a, D: ?Sized, S, A> Unpin for InlineDyn<'a, D, S, A> where
    D: Unpin
[src]

impl<'a, D: ?Sized, S, A> UnwindSafe for InlineDyn<'a, D, S, A> where
    D: UnwindSafe,
    <A as Align>::Output: UnwindSafe,
    <S as Size>::Output: UnwindSafe
[src]

Blanket Implementations

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

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

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

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

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

impl<F> IntoFuture for F where
    F: Future
[src]

type Output = <F as Future>::Output

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

The output that the future will produce on completion.

type Future = F

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

Which kind of future are we turning this into?

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T> Same<T> for T[src]

type Output = T

Should always be Self

impl<T> ToString for T where
    T: Display + ?Sized
[src]

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

The type returned in the event of a conversion error.