摘要:
环境 Rust 1.56.1 VSCode 1.61.2 概念 参考:https://doc.rust-lang.org/rust-by-example/trait/dyn.html 示例 由于 rust 在编译时需要知道占用多少栈空间,所以不能直接返回一个 trait,因为不同的 trait 实现 阅读全文
posted @ 2021-12-23 18:13
jiangbo4444
阅读(210)
评论(0)
推荐(0)
摘要:
环境 Rust 1.56.1 VSCode 1.61.2 概念 参考:https://doc.rust-lang.org/rust-by-example/trait/ops.html 示例 在 rust 中,运算符可以通过实现 trait 来进行重载,可以重载的运算符参考:https://doc.r 阅读全文
posted @ 2021-12-23 18:13
jiangbo4444
阅读(487)
评论(0)
推荐(0)
摘要:
环境 Rust 1.56.1 VSCode 1.61.2 概念 参考:https://doc.rust-lang.org/rust-by-example/trait/derive.html 示例 编译器可以通过 #[derive] 属性提供派生(自动实现)功能,以下 trait 支持派生: 比较 t 阅读全文
posted @ 2021-12-23 18:12
jiangbo4444
阅读(188)
评论(0)
推荐(0)
摘要:
环境 Rust 1.56.1 VSCode 1.61.2 概念 参考:https://doc.rust-lang.org/rust-by-example/trait.html 示例 trait 一般翻译成特质,之后的内容不翻译,类似其它语言中的接口。 main.rs struct Sheep { n 阅读全文
posted @ 2021-12-23 18:11
jiangbo4444
阅读(95)
评论(0)
推荐(0)
摘要:
环境 Rust 1.56.1 VSCode 1.61.2 概念 参考:https://doc.rust-lang.org/stable/rust-by-example/generics/assoc_items/the_problem.html 示例 在使用泛型的过程中,有时候可能会觉得不方便,以下是 阅读全文
posted @ 2021-12-23 18:10
jiangbo4444
阅读(69)
评论(0)
推荐(0)
摘要:
环境 Rust 1.56.1 VSCode 1.61.2 概念 参考:https://doc.rust-lang.org/rust-by-example/scope/lifetime/elision.html 示例 在大多数的情况下,编译器可以推断出生存期,所以我们可以省略生存期标注。 main.r 阅读全文
posted @ 2021-12-23 17:59
jiangbo4444
阅读(58)
评论(0)
推荐(0)
摘要:
环境 Rust 1.56.1 VSCode 1.61.2 概念 参考:https://doc.rust-lang.org/rust-by-example/scope/lifetime/static_lifetime.html 示例 静态生存期使用 ‘static 表示, main.rs // 静态生 阅读全文
posted @ 2021-12-23 17:58
jiangbo4444
阅读(67)
评论(0)
推荐(0)
摘要:
环境 Rust 1.56.1 VSCode 1.61.2 概念 参考:https://doc.rust-lang.org/rust-by-example/scope/lifetime/lifetime_coercion.html 示例 main.rs // Rust 自动推导了生存期,两个参数都被申 阅读全文
posted @ 2021-12-23 17:57
jiangbo4444
阅读(68)
评论(0)
推荐(0)
摘要:
环境 Rust 1.56.1 VSCode 1.61.2 概念 参考:https://doc.rust-lang.org/rust-by-example/scope/lifetime/lifetime_bounds.html 示例 main.rs use std::fmt::Debug; // 包含 阅读全文
posted @ 2021-12-23 17:56
jiangbo4444
阅读(62)
评论(0)
推荐(0)