我相信您采取的方法与您的目标不同。据我了解,您希望在学习如何使用这些集合时将其打印出来。以下是您提到的三个系列的示例。使用每个集合,.to_vec()
您可以在运行测试时很好地看到结果。
use near_sdk::{collections::Map, collections::Vector, collections::Set};
…
// you can place this inside a test
let mut my_near_vector: Vector<String> = Vector::new(b"something".to_vec());
my_near_vector.push(&"aloha".to_string());
my_near_vector.push(&"honua".to_string());
println!("Vector {:?}", my_near_vector.to_vec());
let mut my_near_map: Map<String, String> = Map::new(b"it's a dictionary".to_vec());
my_near_map.insert(&"aardvark".to_string(), &"a nocturnal burrowing mammal with long ears".to_string());
my_near_map.insert(&"beelzebub".to_string(), &"a fallen angel in Milton's Paradise Lost".to_string());
println!("Map {:?}", my_near_map.to_vec());
let mut my_near_set: Set<String> = Set::new(b"phonetic alphabet".to_vec());
my_near_set.insert(&"alpha".to_string());
my_near_set.insert(&"bravo".to_string());
println!("Set {:?}", my_near_set.to_vec());
如果您随后cargo test -- --nocapture
在项目中运行,您将看到如下输出:
running 1 test
Vector ["aloha", "honua"]
Map [("aardvark", "a nocturnal burrowing mammal with long ears"), ("beelzebub", "a fallen angel in Milton\'s Paradise Lost")]
Set ["alpha", "bravo"]
test tests::demo ... ok