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>
impl<B, T> IteratorAsRefSlice<B, T>
Trait Implementations§
source§impl<B, T> Bake for IteratorAsRefSlice<B, T>
impl<B, T> Bake for IteratorAsRefSlice<B, T>
source§fn bake(&self, ctx: &CrateEnv) -> TokenStream
fn bake(&self, ctx: &CrateEnv) -> TokenStream
source§impl<B, T> BakeSize for IteratorAsRefSlice<B, T>
impl<B, T> BakeSize for IteratorAsRefSlice<B, T>
source§fn borrows_size(&self) -> usize
fn borrows_size(&self) -> usize
Returns the size
source§impl<B: Default, T> Default for IteratorAsRefSlice<B, T>
impl<B: Default, T> Default for IteratorAsRefSlice<B, T>
source§fn default() -> IteratorAsRefSlice<B, T>
fn default() -> IteratorAsRefSlice<B, T>
Returns the “default value” for a type. Read more
source§impl<B, T> Deref for IteratorAsRefSlice<B, T>
impl<B, T> Deref for IteratorAsRefSlice<B, T>
source§impl<B, T> DerefMut for IteratorAsRefSlice<B, T>
impl<B, T> DerefMut for IteratorAsRefSlice<B, T>
source§impl<B, T> From<B> for IteratorAsRefSlice<B, T>
impl<B, T> From<B> for IteratorAsRefSlice<B, T>
source§impl<B, T> FromIterator<T> for IteratorAsRefSlice<B, T>
impl<B, T> FromIterator<T> for IteratorAsRefSlice<B, T>
source§fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
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>where
B: RefUnwindSafe,
T: RefUnwindSafe,
impl<B, T> Send for IteratorAsRefSlice<B, T>
impl<B, T> Sync for IteratorAsRefSlice<B, T>
impl<B, T> Unpin for IteratorAsRefSlice<B, T>
impl<B, T> UnwindSafe for IteratorAsRefSlice<B, T>where
B: UnwindSafe,
T: UnwindSafe,
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
Mutably borrows from an owned value. Read more