pub struct ImplFor<'a, P: Parent> { /* private fields */ }
Expand description
A helper struct for implementing a trait for a given struct or enum.
Implementations§
source§impl<'a, P: Parent> ImplFor<'a, P>
impl<'a, P: Parent> ImplFor<'a, P>
sourcepub fn generate_const<'s>(
&'s mut self,
name: impl Into<String>,
ty: impl Into<String>
) -> GenConst<'s, 'a, P>
pub fn generate_const<'s>( &'s mut self, name: impl Into<String>, ty: impl Into<String> ) -> GenConst<'s, 'a, P>
Add a const to the trait implementation
generator.impl_for("Foo")
.generate_const("BAR", "u8")
.with_value(|b| {
b.push_parsed("5")?;
Ok(())
})?;
Generates:
ⓘ
impl Foo for <struct or enum> {
const BAR: u8 = 5;
}
sourcepub fn impl_type(
&mut self,
name: impl AsRef<str>,
value: impl AsRef<str>
) -> Result
pub fn impl_type( &mut self, name: impl AsRef<str>, value: impl AsRef<str> ) -> Result
Add a type to the impl
generator.impl_for("Foo").impl_type("Bar", "u8")
results in code like:
ⓘ
impl Foo for <struct or enum> {
type Bar = u8;
}
sourcepub fn modify_generic_constraints<CB>(&mut self, cb: CB) -> Result<&mut Self>
pub fn modify_generic_constraints<CB>(&mut self, cb: CB) -> Result<&mut Self>
Modify the generic constraints of a type. This can be used to add additional type constraints to your implementation.
ⓘ
// Your derive:
#[derive(YourTrait)]
pub struct Foo<B> {
...
}
// With this code:
generator
.impl_for("YourTrait")
.modify_generic_constraints(|generics, constraints| {
for g in generics.iter_generics() {
constraints.push_generic(g, "YourTrait");
}
})
// will generate:
impl<B> YourTrait for Foo<B>
where B: YourTrait // <-
{
}
Trait Implementations§
Auto Trait Implementations§
impl<'a, P> Freeze for ImplFor<'a, P>
impl<'a, P> RefUnwindSafe for ImplFor<'a, P>where
P: RefUnwindSafe,
impl<'a, P> !Send for ImplFor<'a, P>
impl<'a, P> !Sync for ImplFor<'a, P>
impl<'a, P> Unpin for ImplFor<'a, P>
impl<'a, P> !UnwindSafe for ImplFor<'a, P>
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