简体   繁体   English

在Rust中指定或导入Signed特性的推荐方式是什么?

[英]What is the recommended way to specify or import the Signed trait in Rust?

The Signed trait used to exist in the standard library , but it's gone now. 标准库中曾经存在Signed特征,但是现在不存在了。 A year ago, someone asked about implementing signed traits on reddit , but the thread didn't come to a conclusion, and the author moved on to ask again on the Rust language Discourse site with similar results . 一年前, 有人问过关于在reddit上实现签名特征的问题 ,但是线索并没有得出结论,因此作者继续在Rust语言Discourse网站上再次询问,结果相似

Now there's a Signed trait in the num crate , but I have two concerns: 现在, num Crate中有一个Signed特性,但是我有两个问题:

1) I don't really understand if importing a crate into my project has more overhead in the resulting file size, especially if I only use one trait from it. 1)我不太了解将板条箱导入项目是否会增加文件大小,特别是如果我仅使用其中一个特征。

2) Given the apparent instability of this kind of trait, I'm now leery of adding another dependency in my project if it's not going to stay stable and compatible. 2)考虑到这种特性的明显不稳定,如果不想保持稳定和兼容,我现在很乐意在项目中添加另一个依赖项。

What's the right course to chart here? 在这里绘制图表的正确路线是什么?

Use the crate. 使用板条箱。 The compiler will ensure that an efficient binary is created. 编译器将确保创建有效的二进制文件。 You probably won't notice any interesting change in your file size. 您可能不会注意到文件大小有任何有趣的变化。 Cargo will ensure that actually using the crate is easy. 货物将确保实际使用板条箱很容易。

The "stability" of the trait isn't an inherent property of the trait. 特性的“稳定性”不是特性的固有属性。 Mostly, the usefulness of the trait is questionable. 大多数情况下,该特性的有用性值得怀疑。 The standard library has to be conservative — anything present there has to be supported for the entire life of Rust 1.x (and there are no plans for a Rust 2.x). 标准库必须是保守的-Rust 1.x整个生命周期都必须支持其中的所有内容 (并且没有针对Rust 2.x的计划)。 Adding stuff to the standard library is thus very constrained. 因此,向标准库中添加内容非常受限制。

This is why crates are such first-class citizens. 这就是为什么板条箱是这样的头等公民。 The decision is now up to the maintainers of the num crate for how long to support the trait. 现在决定由数字存储箱的维护者决定支持该特征多长时间。 If they follow semver (and they should), it should be very obvious if they ever drop support for it. 如果他们遵循semver(并且应该这样做),那么一旦他们放弃对它的支持就应该非常明显。 Also, once you have chosen a version of the crate to compile against, it will never change until you do a cargo update , so you are safe to use it. 另外,一旦您选择了要编译的板条箱版本,它就不会更改,直到您进行一次cargo update为止,因此您可以放心使用它。

In the worst of the worst cases, say the num crate decides to drop the trait. 在最坏的情况下,说最坏的决定是放弃该特性。 In that case, you can simply copy the implementation and produce your own crate. 在这种情况下, 可以简单地复制实现并生成自己的板条箱。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为Windows窗体应用程序创建依赖关系的推荐方法是什么? - what is a recommended way to create a dependency for a windows forms application? Django,在块中声明和解决JavaScript依赖关系的推荐方法 - Django, recommended way to declare and solve JavaScript dependencies in blocks 有没有办法在 composer.json 中指定二进制文件必须可用? - Is there a way to specify in composer.json that a binary must be available? “pom”类型依赖与范围“import”和没有“import”之间有什么区别? - What is the difference between “pom” type dependency with scope “import” and without “import”? 有没有一种方法可以将`require`和`import`s限制在函数内部? - Is there a way to scope `require`s and `import`s to the inside of a function? Maven脚本是否可以自动下载我在pom中指定的依赖罐 - Is there a way for maven script to automatically download dependent jars of dependencies i specify in a pom 有人能告诉我一个好的依赖矩阵是什么样的,并说明原因吗? - Can someone show me what a good dependency matrix looks like and specify why? 导入com.facebook.share.internal.ShareConstants;的依赖性是什么? - What's the dependency of import com.facebook.share.internal.ShareConstants;? 推荐的缓存控制方法? - Recommended cache control method? 是串联从另一个“导入”一个JS库的唯一方法? - is concatenating the only way to 'import' one JS lib from another?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM