Fixed-size byte string literals (RFC 339)
This commit is contained in:
parent
bfac337daa
commit
1e9bef916f
10 changed files with 100 additions and 43 deletions
|
|
@ -13,9 +13,13 @@
|
|||
|
||||
static FOO: u8 = b'\xF0';
|
||||
static BAR: &'static [u8] = b"a\xF0\t";
|
||||
static BAR_FIXED: &'static [u8; 3] = b"a\xF0\t";
|
||||
static BAZ: &'static [u8] = br"a\n";
|
||||
|
||||
pub fn main() {
|
||||
let bar: &'static [u8] = b"a\xF0\t";
|
||||
let bar_fixed: &'static [u8; 3] = b"a\xF0\t";
|
||||
|
||||
assert_eq!(b'a', 97u8);
|
||||
assert_eq!(b'\n', 10u8);
|
||||
assert_eq!(b'\r', 13u8);
|
||||
|
|
@ -44,19 +48,23 @@ pub fn main() {
|
|||
b", expected);
|
||||
let expected: &[_] = &[97u8, 240u8, 9u8];
|
||||
assert_eq!(BAR, expected);
|
||||
assert_eq!(BAR_FIXED, expected);
|
||||
assert_eq!(bar, expected);
|
||||
assert_eq!(bar_fixed, expected);
|
||||
|
||||
let val: &[_] = &[97u8, 10u8];
|
||||
let val = &[97u8, 10u8];
|
||||
match val {
|
||||
b"a\n" => {},
|
||||
_ => panic!(),
|
||||
}
|
||||
|
||||
let buf = vec!(97u8, 98, 99, 100);
|
||||
assert_eq!(match &buf[0..3] {
|
||||
b"def" => 1_usize,
|
||||
b"abc" => 2_usize,
|
||||
_ => 3_usize
|
||||
}, 2);
|
||||
// FIXME: There are no DST coercions &[T; N] -> &[T] in patterns
|
||||
// let buf = vec!(97u8, 98, 99, 100);
|
||||
// assert_eq!(match &buf[0..3] {
|
||||
// b"def" => 1_usize,
|
||||
// b"abc" => 2_usize,
|
||||
// _ => 3_usize
|
||||
// }, 2);
|
||||
|
||||
let expected: &[_] = &[97u8, 92u8, 110u8];
|
||||
assert_eq!(BAZ, expected);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue