I need help in this contradiction

โš“ Rust    ๐Ÿ“… 2025-11-20    ๐Ÿ‘ค surdeus    ๐Ÿ‘๏ธ 8      

surdeus

(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

Read full topic

๐Ÿท๏ธ Rust_feed