我想用伪代码执行以下操作:
在 Rust 中,我尝试了类似这样的东西:
如何解决这个问题?
(a, b, c) = (HashSet(...), HashSet(...), HashSet(...))
(a, b, c) = (a - b - c, b - a - c, c - a - b)
在 Rust 中,我尝试了类似这样的东西:
fn get_random_set(...) -> HashSet<String> {
...
}
// Sets of randomly generated "words" that define behavior of the whole program.
let action_plus: HashSet<String> = get_random_set();
let action_minus: HashSet<String> = get_random_set();
let action_new_line: HashSet<String> = get_random_set();
现在我们要从这些HashSet
中排除所有常见的"words"。
我了解到difference
和union
方法返回Difference
和Union
迭代器。如果我这样做:
let action_plus = HashSet::from(action_minus.union(&action_new_line).collect::<Vec<String>>());
我收到这个:
the trait `From<Vec<String>>` is not implemented for `HashSet<_, _>`
如何解决这个问题?
from
并不是答案,而是在into_iter()
上使用collect()
。 - tadman