-
Rust❤️BalancedI{8,16,32,etc.} type코딩Coding/★★Rust★★최신동향★및관련글 2022. 10. 1. 21:32728x90
BalancedI{8,16,32,etc.} type
Rust has std::num::NonZeroI8 for example, in which zero is made into a niche and so Option<NonZeroI8> is the same size as i8 (one byte). But it would seem more useful to define BalancedI8 for which -128 is the niche and zero is available. This would be "balanced" in the sense that its minimum is -127 and maximum is 127, and since it has a niche Option<BalancedI8> would also be able to occupy one byte.
Am I correct in understanding that this can't just be done by the standard library as it stands because of how Rust's compiler currently expresses niches? From the compiler's point of view this -128 niche is "in the middle" of the values since it is 0b10000000 which is between 0b01111111 (+127) and 0b10000001 (-127)
If that's correct, is there already work to try to be able to put a niche somewhere else? Or to allow it to work for signed values like this? Is there some subtlety that I'm missing beyond just a few places in the compiler which care?
This train of thought was inspired by Jonathan Mueller's "New integer types" C++ post but I wanted to think particularly about the balanced integer type.
https://www.reddit.com/r/rust/comments/xshdxh/balancedi81632etc_type/?utm_source=share&utm_medium=ios_app&utm_name=iossmf반응형'코딩Coding > ★★Rust★★최신동향★및관련글' 카테고리의 다른 글
How I landed a Rust job' | Rust and Cpp Cardiff Meetup (2) 2022.11.01 Web-native Rust apps (what will YOU build?) [RUST-12] (0) 2022.10.22 github에서 최신 Rust❤ 트랜드 검색하기 (0) 2022.10.20 Rust❤️How to understand why Box<&’longer T> is a subtype of Box<&’shorter T>> (0) 2022.10.02 Rust in industry (0) 2022.09.28 Rust❤️When do you put logic in mod.rs? (0) 2022.09.25 C/C++ deprecated 발언 쎄다 ㅋㅋ 이제 고전 언어로 가는구나 ㅎㅎC는 ㅎㅎ (2) 2022.09.21 Full Event | Rust Day on Google Open Source Live (0) 2022.09.18