I need help in this contradiction
โ Rust ๐ 2025-11-20 ๐ค surdeus ๐๏ธ 8(Sorry if its clickbaity; I not good at โtitlingโ the post)
Look more down as such there more specific example what I meant; if your confused on this example
How do you fix this?
For example
trait Example {
type Whatever;
fn etc() -> Self::Whatever;
}
struct UnitValue;
impl<'a> Example for UnitValue {
type Whatever = &'a UnitValue;
// Assuming you can't do 'static lifetime onto this type
fn etc() -> Self::Whatever {
&UnitValue
}
}
Assuming the etc() function uses a reference OF SELF as input and outputs a reference OF ITS OWN (e.g &type.field, etc) OR SOME SORT (&โstatic 5, etc), AND cannot change the trait (for example from a lib)
This errors says โa is unconstrained
trait Example {
type Whatever;
fn etc() -> Self::Whatever;
}
struct UnitValue;
impl Example for UnitValue {
type Whatever<'a> = &'a UnitValue;
// Assuming you can't do 'static lifetime onto this type
fn etc() -> Self::Whatever {
&UnitValue
}
}
This doesnโt work as such conflicts with the trait implementation
Can somebody help please?
9 posts - 4 participants
๐ท๏ธ Rust_feed