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 new_lifetimes_depend_on_existing(self) -> Self
pub fn new_lifetimes_depend_on_existing(self) -> Self
Make the new lifetimes added by Generator::impl_for_with_lifetimes depend on the existing lifetimes from the original derive.
See impl_for_with_lifetimes for more information.
Calling this method in any other context has no effect.
§Panics
Panics if an internal invariant is violated.
Sourcepub const fn make_unsafe(self) -> Self
pub const fn make_unsafe(self) -> Self
Add unsafe generic parameters to the trait implementation.
Make the generated `impl` block unsafe.
Generates:
```ignore
unsafe impl Foo for Bar { }Sourcepub fn with_trait_generics<ITER>(self, generics: ITER) -> Self
pub fn with_trait_generics<ITER>(self, generics: ITER) -> Self
Add generic parameters to the trait implementation.
generator.impl_for("Foo").with_trait_generics(["Baz"]);Generates:
ⓘ
impl Foo for <struct or enum> {
const BAR: u8 = 5;
}Sourcepub fn with_impl_generics<ITER>(self, generics: ITER) -> Self
pub fn with_impl_generics<ITER>(self, generics: ITER) -> Self
Sourcepub fn impl_outer_attr(&mut self, attr: impl AsRef<str>) -> Result
pub fn impl_outer_attr(&mut self, attr: impl AsRef<str>) -> Result
Sourcepub fn impl_inner_attr(&mut self, attr: impl AsRef<str>) -> Result
pub fn impl_inner_attr(&mut self, attr: impl AsRef<str>) -> Result
Sourcepub fn generate_const(
&mut self,
name: impl Into<String>,
ty: impl Into<String>,
) -> GenConst<'_>
pub fn generate_const( &mut self, name: impl Into<String>, ty: impl Into<String>, ) -> GenConst<'_>
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 generate_fn(&mut self, name: impl Into<String>) -> FnBuilder<'_, Self>
pub fn generate_fn(&mut self, name: impl Into<String>) -> FnBuilder<'_, Self>
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 // <-
{
}§Errors
Returns an error if parsing fails.
Trait Implementations§
Auto Trait Implementations§
impl<'a, P> !Send for ImplFor<'a, P>
impl<'a, P> !Sync for ImplFor<'a, P>
impl<'a, P> !UnwindSafe for ImplFor<'a, P>
impl<'a, P> Freeze for ImplFor<'a, P>
impl<'a, P> RefUnwindSafe for ImplFor<'a, P>where
P: RefUnwindSafe,
impl<'a, P> Unpin for ImplFor<'a, P>
impl<'a, P> UnsafeUnpin 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