我无法弄清楚如何创建一个类型,以便:
type CountryCode = &[char] // only 3 chars in it, no more
Run Code Online (Sandbox Code Playgroud)
是否可以使用type,或者我应该使用struct?
使用示例代码扩展@Levans的注释:
type CountryCode = [char; 3];
fn print_it(code: CountryCode) {
println!("{:?}", code);
}
fn main() {
let code: CountryCode = ['u', 's', 'a'];
print_it(code);
}
Run Code Online (Sandbox Code Playgroud)