Type-erasue? in Rust

Yes, but that's also true if you implemented part B too.

Coercing to a dyn Trait + '_, generally. One might also include passing around *mut () with some other way of tracking the type at runtime, I suppose.

I can't think of a specific phrase for factoring out the non-generic functionality (which doesn't mean such a phrase doesn't exist). It's related to composition though.

pub struct NonGenericParts { /* ... */ }
impl NonGenericParts { /* ... */ }

struct S<T> {
    ngp: NonGenericParts,
    // ...
}

// then
impl<T> S<T> { /* forward `NonGenericParts` methods */ }
// and/or
impl<T> AsRef<NonGenericParts> for S<T> { /* ... */ }
impl<T> AsMut<NonGenericParts> for S<T> { /* ... */ }

N.b. my understanding/use of the phrase was built organically, not from some authoritative source I can cite.

3 Likes