我有一个包,我想添加一个可选功能。我已在 Cargo.toml 中添加了适当的部分:
[features]
foo = []
Run Code Online (Sandbox Code Playgroud)
我为宏的基本功能编写了一个实验测试cfg!:
#[test]
fn testing_with_foo() {
assert!(cfg!(foo));
}
Run Code Online (Sandbox Code Playgroud)
看起来我可以在测试期间通过以下选项之一激活功能--features:--all-features
(master *=) $ cargo help test
cargo-test
Execute all unit and integration tests and build examples of a local package
USAGE:
cargo test [OPTIONS] [TESTNAME] [-- <args>...]
OPTIONS:
-q, --quiet Display one character per test instead of one line
...
--features <FEATURES>... Space-separated list of features to activate
--all-features Activate all available features
Run Code Online (Sandbox Code Playgroud)
不过,两者cargo test --features foo testing_with_foo都不起作用。 …
我想实现一个线索为整数索引的序列。为了效率起见,重要的是节点的子节点通过索引序列而不是某种映射与节点相关联。为了说明基本思想,这里有一个 Ruby 实现:
require 'virtus'
class TrieNode
include Virtus.model
attribute :terminal, Boolean, default: false
attribute :children, Array, default: []
def add(i, vec)
if i == vec.length
terminal = true
else
( children[vec[i]] ||= TrieNode.new ).add i + 1, vec
end
end
end
Run Code Online (Sandbox Code Playgroud)
这是 Perl 中的相同内容:
package TrieNode;
use Moo;
has terminal => ( is => 'rw' );
has children => ( is => 'ro', default => sub { [] } );
sub add {
my ( $self, $i, …Run Code Online (Sandbox Code Playgroud)