Struct databake::converter::AsStaticStr
source · #[repr(transparent)]pub struct AsStaticStr<T>(pub T)
where
T: AsRef<str>;
Expand description
Let Bake
output a &'static str
for anything that can be AsRef<str>
.
It can be helpful if the type needs to be constructed (e.g. String
, Cow<str>
) but should result in a &'static str
.
This requires that the crate using the generated data needs a different struct.
use databake::{converter::AsStaticStr, Bake};
#[derive(Bake)]
#[databake(path = my_crate)]
struct Data {
number: usize,
string: AsStaticStr<String>, // can be written as StringAsStaticStr
}
let data = Data {
number: 6,
string: 6.to_string().into(),
};
assert_eq!(
data.bake(&Default::default()).to_string(),
r#"my_crate :: Data { number : 6usize , string : "6" , }"#
);
mod my_crate {
struct Data {
number: usize,
string: &'static str,
}
}
Tuple Fields§
§0: T
Implementations§
Trait Implementations§
source§impl<T> Bake for AsStaticStr<T>
impl<T> Bake for AsStaticStr<T>
source§fn bake(&self, _ctx: &CrateEnv) -> TokenStream
fn bake(&self, _ctx: &CrateEnv) -> TokenStream
source§impl<T> BakeSize for AsStaticStr<T>
impl<T> BakeSize for AsStaticStr<T>
source§fn borrows_size(&self) -> usize
fn borrows_size(&self) -> usize
Returns the size
source§impl<T> Default for AsStaticStr<T>
impl<T> Default for AsStaticStr<T>
source§fn default() -> AsStaticStr<T>
fn default() -> AsStaticStr<T>
Returns the “default value” for a type. Read more
source§impl<T> Deref for AsStaticStr<T>
impl<T> Deref for AsStaticStr<T>
source§impl<T> DerefMut for AsStaticStr<T>
impl<T> DerefMut for AsStaticStr<T>
Auto Trait Implementations§
impl<T> Freeze for AsStaticStr<T>where
T: Freeze,
impl<T> RefUnwindSafe for AsStaticStr<T>where
T: RefUnwindSafe,
impl<T> Send for AsStaticStr<T>where
T: Send,
impl<T> Sync for AsStaticStr<T>where
T: Sync,
impl<T> Unpin for AsStaticStr<T>where
T: Unpin,
impl<T> UnwindSafe for AsStaticStr<T>where
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