menu
Extensions
Like impl in Rust but a little broader.
Extensions
Rust has
implblocks for as the sole mechanism for attaching members to nominal targetsTS++ has its as an additional mechanism
like
implin Rust but a little broaderinherent, anonymous, named extensions
E / T, T may be local or imported
extension of Textension E of Texport extension of Texport extension E of Tan inhernt extension beside its target is visible wherever the target is visible
an anonymous extension on a foreign target is visible only in its declaring file
a named foreign extension must be imported explicitly
extension<T> of T: blanket extensionstructural types, unions, and intersections cannot receive extensions
rustc coherence
overlapping implementations of one interface for one type, including blanket overlap, are errors
no orphan rule?
extension members are lexical, but
implementscontributes a program-wide relation whenever its module is in the programglobal extensions considered for impls (not import order)
member overloading only within a single declaration block (extension or itme declaration)
also for @unsafe impls
1newtype UserId = string;2 3extension of UserId {4 value(this): string {5 string(this)6 }7}- extension members are lexical and import-scoped
- interface implementations participate in the whole program (even if not imported/exported)