简体   繁体   English

在稳定的 Rust 中为大量数组实现特征的惯用方法是什么?

[英]What is the idiomatic way to implement a trait for a large number of arrays in stable Rust?

Given my trait T and a large set of std / core arrays ( not slices ), How can I make implementations of T for these arrays available to other crates on stable Rust?鉴于我的 trait T和一大组std / core数组(不是 slices ),我怎样才能使这些数组的T实现可用于稳定的 Rust 上的其他板条箱?

From searching around, it seems my only options (that don't sidestep this problem) are to:通过四处搜索,似乎我唯一的选择(不回避这个问题)是:

  1. wait for a release of rust with a stable implementation of rfc 2000: https://github.com/rust-lang/rust/issues/44580等待稳定实现 rfc 2000 的 Rust 发布: https : //github.com/rust-lang/rust/issues/44580
  2. implement the trait manually for each and every array.为每个数组手动实现特征。

Option 1 is not acceptable.选项 1 是不可接受的。 Option 2 leads to very long compile times (especially when the set of arrays exceeds 5000 types).选项 2 会导致很长的编译时间(尤其是当数组集超过 5000 种类型时)。 Hiding every single implementation behind its own feature, ie feature impl-t-for-array-N conditionally compiles in an implementation of T for array [U;N] , does considerably lower compilation time.将每个单独的实现隐藏在它自己的特性后面,即特性impl-t-for-array-N有条件地在T的实现中编译为数组[U;N] ,确实大大降低了编译时间。 (Compilation times went from from tens of minutes to a couple of seconds). (编译时间从几十分钟变成了几秒钟)。 However, the delay caused by processing thousands of features is still noticeable.然而,处理数千个特征造成的延迟仍然很明显。

Is using features and manual implementations the most idiomatic way to handle this problem on stable rust, or is there a more idiomatic way I'm missing?使用功能和手动实现是在稳定 Rust 上处理这个问题的最惯用的方法,还是我缺少更惯用的方法?

Is using features and manual implementations the most idiomatic way to handle this problem on stable rust使用功能和手动实现是在稳定锈上处理这个问题的最惯用的方法

Yes.是的。 For example, check Debug trait and its sources - as you can see rust uses special macro to implement it for arrays with length <= 32例如,检查Debug trait 及其来源 - 正如你所看到的,rust 使用特殊的宏来为长度 <= 32 的数组实现它

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

相关问题 我应该对非常大的 arrays 使用 std::array 吗? 什么是惯用的替代方法? - Should I be using std::array for very large arrays? What is the idiomatic alternative? 在MATLAB中删除或更改数组中大量条目的最快方法是什么? - What's the fastest way to remove or change large number of entries in arrays in MATLAB? 在 Javascript 中处理大型 arrays 的最佳方法是什么? - What is the best way to process large arrays in Javascript? 实现可变长度数组的最佳方法是什么? - What is best way to implement variable length arrays? 用另一个列表(也是数组)扩展(n元组或列表)列表的惯用F#方法是什么? - What would be an idiomatic F# way to scale a list of (n-tuples or list) with another list, also arrays? 在 numpy 中获得 2d arrays 的行相等的简洁/惯用方法是什么? - What's concise/idiomatic way to get row-wise equality of 2d arrays in numpy? 在大量数组中搜索数字的优雅方法(jQuery) - Elegant way to search a number in a large amount of arrays (jQuery) 在PHP中将大型CSV文件解析为数组的最快方法是什么? - What is the fastest way to parse large CSV files into arrays in PHP? ReactJS的惯用方式是什么? 州? - What is the idiomatic ReactJS way to deal with ?initial? state? 在Java中初始化大量数组? - Initializing large number of arrays in Java?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM