cost 86 ms
应该如何围绕 Rust 的孤儿规则设计库 crate? - How should library crates be designed around Rust's Orphan Rule?

我对孤儿利益规则的理解是: 对于 Type 上的 Trait 的任何impl , Trait 或 Type 必须与impl定义在同一个 crate 中。 或等效地: 不可能在外部 crate 中定义的类型上实现在外部 crate 中定义的特征。 所以问题是,应该如何设计一个库 c ...

在单独的 mod 中使用实现时出现多个 impl 错误 - Multiple `impl`s error while use-ing implementations within separated mods

深入研究孤儿规则的主题,我最终得到了一种通过在实现板条箱之外定义的类型的特征实现。 但结果,我现在有另一个关于 trait 实现的问题。 以下示例运行良好: 结果: 但是,如果我将主要替换为: 得到以下错误: 为什么会出现这样的错误,而“使用 c3::...;” 和“使用 c4::. ...

有没有办法设计一个允许任何类型实现的特征,即使实现者既不拥有类型也不拥有特征? - Is there a way to design a trait that allows its implementation by any type even if the implementer owns neither the type nor the trait?

在一般情况下,不可能在 crate C1 中为 crate C3 中定义的 Type 实现 C2 中定义的 trait,假设 C1、C2、C3 不同 但是有没有故意设计一个特征的技巧,以便允许这样的实现? ...


排序:
质量:
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM