带后缀的数字文字(例如0u8)在Rust中意味着什么? [英] What do number literals with a suffix, like 0u8, mean in Rust?

查看:140
本文介绍了带后缀的数字文字(例如0u8)在Rust中意味着什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读 The Rust Programming语言,并且遇到过这种表示法: 0u8 .

I'm reading through The Rust Programming Language and have encountered this notation: 0u8.

let some_u8_value = 0u8;
match some_u8_value {
    1 => println!("one"),
    3 => println!("three"),
    5 => println!("five"),
    7 => println!("seven"),
    _ => (),
}

在网上搜索后,我发现了很多使用这种符号的示例( 0b01001100u8 0x82u8 200u8 ),但是这个符号究竟是什么意思?

After searching the web, I've found lots of examples of this notation being used (0b01001100u8, 0x82u8, 200u8), but what exactly does this notation mean?

推荐答案

后缀字面量

搜索后,我在

...除字节文字外的所有数字文字都允许使用类型后缀,例如 57u8 ...

所以 0u8 是数字0,是一个无符号的8位整数.

So 0u8 is the number 0 as an unsigned 8-bit integer.

这些被称为后缀文字".并且在以示例为例" 中进行了详细讨论

These are referred to as "suffixed literals" and are discussed at length in Rust By Example.

这篇关于带后缀的数字文字(例如0u8)在Rust中意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆