Login
You're viewing the functional.cafe public feed.
  • Nov 19, 2026, 1:11 AM

    Second question. Can the following Swift program be expressed in Rust?

    protocol S {
    associatedtype A
    associatedtype B
    associatedtype C: S
    where Self == Self.C.C,
    Self.B == Self.C.A
    }

    func f<T: S>(x: T.C.B) -> T.A {
    return x
    }

    I tried using trait bounds, but then f() does not type check:

    trait S {
    type A;
    type B;
    type C: S<A = Self::B, C = Self>;
    }

    fn f<T: S>(x: <T::C as S>::B) -> T::A {
    return x;
    // note: expected associated type `<T as S>::A'
    // found associated type `<<T as S>::C as S>::B'
    }

    💬 0🔄 3⭐ 0