Rust 程序设计语言 简体中文版 1.85.0
语言中,有两个不同的运算符来调用方法:. 直接在对象上调用方法,而 -> 在一个对象的指针上调用方法,这时需要先解引用(dereference)指针。换句话 说,如果 object 是一个指针,那么 object->something() 就像 (*object).something() 一样。 110/562Rust 程序设计语言 简体中文版 Rust 并没有一个与 -> 等效的运算符;相反,Rust 有一个叫 referencing and dereferencing)的功能。方法调用是 Rust 中少数几个拥 有这种行为的地方。 它是这样工作的:当使用 object.something() 调用方法时,Rust 会自动为 object 添 加 &、&mut 或 * 以便使 object 与方法签名匹配。也就是说,这些代码是等价的: # # p1.distance(&p2); (&p1).distance(&p2); billion-dollar mistake. At that time, I was designing the first comprehensive type system for references in an object-oriented language. My goal was to ensure that all use of references should be absolutely safe, with0 码力 | 562 页 | 3.23 MB | 9 天前3
共 1 条
- 1