"impl has stricter requirements than trait" even though function signature is identical
⚓ Rust 📅 2026-01-08 👤 surdeus 👁️ 1Hi, in my project I made a trait (CanWriteBox) that I want to implement on my struct. Even though the function signature of the write_box_of function is identical between the trait definition and the implementation, I still get a impl has stricter requirements than trait error.
Below is the code in question isolated:
use std::hash::Hash;
use std::io::{Seek, Write};
use std::marker::PhantomData;
pub trait WriteDomain: Sized {
type Pointer;
type Cat: Eq + Hash + Ord + Default + Clone;
// ...
}
pub trait WriteCtx<Cat>
where
Cat: Eq + Hash + Ord + Default + Clone,
{
type Writer: Write + Seek;
type InnerCtx<'a>: WriteCtx<Cat, Writer = Self::Writer> where Self: 'a;
// ...
}
pub trait CanWriteBox: WriteDomain {
fn write_box_of<W: WriteCtx<Self::Cat>>(
&mut self,
ctx: &mut W,
write_content: impl FnOnce(&mut Self, &mut W::InnerCtx<'_>),
);
}
struct FormatCgfx<C: Eq + Hash + Ord + Default + Clone> {
_marker: PhantomData<C>,
}
impl<C: Eq + Hash + Ord + Default + Clone> WriteDomain for FormatCgfx<C> {
type Pointer = u32;
type Cat = C;
}
impl<C: Eq + Hash + Ord + Default + Clone> CanWriteBox for FormatCgfx<C> {
fn write_box_of<W: WriteCtx<Self::Cat>>(
&mut self,
_ctx: &mut W,
_write_content: impl FnOnce(&mut Self, &mut W::InnerCtx<'_>),
) {
// ...
}
}
I would appreciate help.
5 posts - 2 participants
🏷️ Rust_feed