Giter Site home page Giter Site logo

Comments (3)

ZhangHanDong avatar ZhangHanDong commented on August 19, 2024 2

@jiacai2050

「Trait 继承」是个很严谨的说法,它表达的是 trait 的一种用法,描述 supertrait 和 subtrait 的关系。国外官方 RFC/ 官方论坛/ reddit / stackoverflow 都在用 这个词 来描述 这种用法。

Rust 当然不是 OOP 语言。但是「继承」这个词只能 OOP 专用吗?

赞同你的「trait 继承」本质就是 trait bound 和 「组合」。但你用 「trait 组合」 能表达出 「supertrait和subtrait 的父子关系」吗?

不必抠字眼,这只是个代号。明白背后的意义就可以了。

放心大胆的用 「trait 继承」。你可以给这个词 加个 链接,指向官方定义页面就可以了。

from rust_magazine_2021.

jiacai2050 avatar jiacai2050 commented on August 19, 2024 1

我是本文作者,有些读者反馈「Trait 不能继承 Sized」的说法不是很严谨,会造成误解,因为 Rust 不是 OOP 的语言,说 trait 继承会让初学者以为 Rust 具备 OOP 的特点,其实这里的“继承”更类似于「组合」的概念,官方文档称为 trait bound

本文在投稿 RustMagazine 后,又更新了些内容,感兴趣读者可移步:https://liujiacai.net/blog/2021/04/27/trait-usage/

from rust_magazine_2021.

ZhangHanDong avatar ZhangHanDong commented on August 19, 2024

把 a: b 这种形式 按 限定 理解也行,但其实我们需要一个「父与子」的概念。比如 'long: 'short,在判断协变逆变情况下是需要的。用 继承语义来统一理解是很有必要的。因此我认为,「trait 继承」这个叫法很精准很严谨。

from rust_magazine_2021.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.