swash/
tag.rs

1/// Four byte tag value.
2pub type Tag = u32;
3
4/// Creates a tag from four bytes.
5pub const fn tag_from_bytes(bytes: &[u8; 4]) -> Tag {
6    (bytes[0] as u32) << 24 | (bytes[1] as u32) << 16 | (bytes[2] as u32) << 8 | bytes[3] as u32
7}
8
9/// Creates a tag from the first four bytes of a string, inserting
10/// spaces for any missing bytes.
11pub fn tag_from_str_lossy(s: &str) -> Tag {
12    let mut bytes = [b' '; 4];
13    for (i, b) in s.as_bytes().iter().enumerate().take(4) {
14        bytes[i] = *b;
15    }
16    tag_from_bytes(&bytes)
17}