basic/trait/advance-trait #777
Replies: 75 comments 57 replies
-
有点难懂,要睇多两次。 |
Beta Was this translation helpful? Give feedback.
-
到这卡壳了,休息一下,改天再来 |
Beta Was this translation helpful? Give feedback.
-
哇这一节直接懵了 先跳过了 学会点集合操作刷刷力扣 把Rust用起来再说😂 |
Beta Was this translation helpful? Give feedback.
-
newtype 就是装箱,配合 Deref 自动从箱里拿出值 |
Beta Was this translation helpful? Give feedback.
-
特征定义中的特征约束,算不算是trait的继承? |
Beta Was this translation helpful? Give feedback.
-
哪里有提到trait的继承,官方那本书也没涉及这些内容 |
Beta Was this translation helpful? Give feedback.
-
"感觉很像之前讲过的特征约束,只不过用在了特征定义中而不是函数的参数中" |
Beta Was this translation helpful? Give feedback.
-
跨度有点大啊哥哥们,看不懂了 |
Beta Was this translation helpful? Give feedback.
-
#![allow(unused)] 这段code没有看明白。是指Address的实际类型需要同时实现后边的所有trait吗?也是trait限定? |
Beta Was this translation helpful? Give feedback.
-
修改默认泛型类型参数部分,完整参考代码: use std::ops::Add;
#[derive(Debug)]
struct Millimeters(u32);
struct Meters(u32);
impl Add<Meters> for Millimeters {
type Output = Millimeters;
fn add(self, other: Meters) -> Self::Output {
Millimeters(self.0 + (other.0 * 1000))
}
}
fn main() {
let x = Millimeters(5);
let y = Meters(3);
print!("{:?}", x.add(y));
} |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
好难好难 前面几节看了半天。 这一节就花了我半天时间, 关键是 还很懵逼 |
Beta Was this translation helpful? Give feedback.
-
所有self.0是取出元组结构体第一个字段的意思吗,我看了好久qaq |
Beta Was this translation helpful? Give feedback.
-
懵逼:跳过喽 哈哈 |
Beta Was this translation helpful? Give feedback.
-
第一次插眼,懵逼ing |
Beta Was this translation helpful? Give feedback.
-
trait 用法太多了,需要自己重新总结一遍 |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
感觉Rust的Trait融合了其他语言的多态、接口甚至装饰器之类的很多特性,是个相当复杂的大集合。我看了好几遍都是似懂非懂,关键是不清楚其中一些功能会在开发中如何使用,有什么好处。还是得有个具体的小项目练练手才行。 |
Beta Was this translation helpful? Give feedback.
-
最后为 Wrapper 实现 Deref 特征和重载方法怎么不讲了 |
Beta Was this translation helpful? Give feedback.
-
整个泛型和特征2.8章节读了3-4遍……记不住 |
Beta Was this translation helpful? Give feedback.
-
Rust 简直太自由辣 |
Beta Was this translation helpful? Give feedback.
-
我就眨了一下眼睛,怎么直接看不懂了???? |
Beta Was this translation helpful? Give feedback.
-
特征定义中的特征约束:叫组合呗? |
Beta Was this translation helpful? Give feedback.
-
关联类型那几个例子感觉毫无关联啊?只有懂的人才能看懂? |
Beta Was this translation helpful? Give feedback.
-
impl Add for Point {
type Output = Point;
fn add(self, other: Point) -> Point {
Point {
x: self.x + other.x,
y: self.y + other.y,
}
}
} 按照我的理解,这段实例代码是可以使用泛型来写的,可是应该怎么写呢?尝试了一下写不出来QAQ |
Beta Was this translation helpful? Give feedback.
-
“这里提供一个办法来绕过孤儿规则” 所以新的类型符合 newtype的定义, 但是当你使用这个类型的时候, 就好像在使用原来的类型一样. |
Beta Was this translation helpful? Give feedback.
-
pub trait Iterator { |
Beta Was this translation helpful? Give feedback.
-
好有趣的语言特性啊,没有继承,但有特征定义中的特征约束(虽然不叫继承),大大提高了语言灵活性。 |
Beta Was this translation helpful? Give feedback.
-
basic/trait/advance-trait
https://course.rs/basic/trait/advance-trait.html
Beta Was this translation helpful? Give feedback.
All reactions