Struct databake::converter::IteratorAsRefSlice

source ·
#[repr(transparent)]
pub struct IteratorAsRefSlice<B, T>(pub B, pub PhantomData<T>) where for<'a> &'a B: IntoIterator<Item = &'a T>, T: Bake;
Expand description

Let Bake output a &'static [T] for anything that can be iterated over.

It can be helpful if the type needs to be constructed (e.g. Vec<T>) but should result in a &'static [T].

This requires that the crate using the generated data needs a different struct.

use databake::{converter::IteratorAsRefSlice, Bake};

#[derive(Bake, Default)]
#[databake(path = my_crate)]
struct Data {
    numbers: IteratorAsRefSlice<Vec<usize>, usize>, // can be written as `VecAsRefSlice<usize>`
}

let mut data = Data::default();
data.numbers.push(6);

assert_eq!(
    data.bake(&Default::default()).to_string(),
    r#"my_crate :: Data { numbers : & [6usize ,] , }"#
);

mod my_crate {
    struct Data {
        numbers: &'static [usize],
    }
}

Tuple Fields§

§0: B§1: PhantomData<T>

Implementations§

source§

impl<B, T> IteratorAsRefSlice<B, T>
where for<'a> &'a B: IntoIterator<Item = &'a T>, T: Bake,

source

pub fn into(self) -> B

Trait Implementations§

source§

impl<B, T> Bake for IteratorAsRefSlice<B, T>
where for<'a> &'a B: IntoIterator<Item = &'a T>, T: Bake,

source§

fn bake(&self, ctx: &CrateEnv) -> TokenStream

Returns a TokenStream that would evaluate to self. Read more
source§

impl<B, T> BakeSize for IteratorAsRefSlice<B, T>
where for<'a> &'a B: IntoIterator<Item = &'a T>, T: BakeSize,

source§

fn borrows_size(&self) -> usize

Returns the size
source§

impl<B: Default, T> Default for IteratorAsRefSlice<B, T>
where for<'a> &'a B: IntoIterator<Item = &'a T>, T: Bake + Default,

source§

fn default() -> IteratorAsRefSlice<B, T>

Returns the “default value” for a type. Read more
source§

impl<B, T> Deref for IteratorAsRefSlice<B, T>
where for<'a> &'a B: IntoIterator<Item = &'a T>, T: Bake,

source§

type Target = B

The resulting type after dereferencing.
source§

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

Dereferences the value.
source§

impl<B, T> DerefMut for IteratorAsRefSlice<B, T>
where for<'a> &'a B: IntoIterator<Item = &'a T>, T: Bake,

source§

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

Mutably dereferences the value.
source§

impl<B, T> From<B> for IteratorAsRefSlice<B, T>
where for<'a> &'a B: IntoIterator<Item = &'a T>, T: Bake,

source§

fn from(value: B) -> Self

Converts to this type from the input type.
source§

impl<B, T> FromIterator<T> for IteratorAsRefSlice<B, T>
where B: FromIterator<T>, for<'a> &'a B: IntoIterator<Item = &'a T>, T: Bake,

source§

fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self

Creates a value from an iterator. Read more

Auto Trait Implementations§

§

impl<B, T> Freeze for IteratorAsRefSlice<B, T>
where B: Freeze,

§

impl<B, T> RefUnwindSafe for IteratorAsRefSlice<B, T>

§

impl<B, T> Send for IteratorAsRefSlice<B, T>
where B: Send, T: Send,

§

impl<B, T> Sync for IteratorAsRefSlice<B, T>
where B: Sync, T: Sync,

§

impl<B, T> Unpin for IteratorAsRefSlice<B, T>
where B: Unpin, T: Unpin,

§

impl<B, T> UnwindSafe for IteratorAsRefSlice<B, T>
where B: UnwindSafe, T: UnwindSafe,

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<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.