programmer group

Trust learning - a preliminary study of using structs

It seems very simple to create a struct in trust, and it is easy to get the attribute value. So how to use it? Is ownership involved? If so, what should be done? First, we use an example to find the perimeter of a rectangle fn main() { let width = 36; let height = 18; Println! "Width: {}, height: {} rectangle perimeter: {}", width, height, get_ perimeter(width, height)) } fn get_perimeter(width: u32, height: u32) -> u32...

programmer group

Trust learning - storing keys with associated values in a hash map

Like vectors and strings, hash maps are a common collection.The HashMap < K, V > type stores the mapping of keys of type K to values of type V. It does this through a hash function that determines how to put the keys and values into memory. Create a hash map: //Create an empty hash map and use the insert method for interpolation fn main() { use std::collections::HashMap; let mut scores = HashMap::new(); ...