fourcc-rs
The fourcc-rs crate provides types and macros for working with four-character
codes which are 32-bit numbers, usually represented by four ASCII characters.
FourCCs were heavily used on the classic macintosh platform to identify file and resource types, applications and more.
Check out the Wikpedia Aritcle on FourCCs if you want to know more.
use ;
// Use macro to create a new FourCC from a string or number at compile-time
let bndl = fourcc!;
assert_eq!;
// Use constructor to create a new FourCC from a u32 at run-time
let bndl = new;
assert_eq!;
// Or do the same thing via the From<u32> implementation
let bndl: FourCC = 0x424e444c.into;
assert_eq!;
One of the defining features is that the [fourcc] macro can be used to build
four-character codes at compile time, which allows them to be used in match statements.
use ;
// Imagine reading the code from a file
let code = new;
match code
Features
The crate provides the optional features serde and binrw.
Using the binrw feature, allows you to read FourCCs from any [std::io::Read] + [std::io::Seek]
implementation.
use ;
use BinReaderExt as _;
use io;
let mut reader = new;
let code: FourCC = reader.read_le.unwrap;
assert_eq!;
Similarly enabling the serde feature allows you to read and write FourCCs using
serde.
use ;
let json = "\"BDNL\"";
let code: FourCC = from_str.unwrap;
assert_eq!;
// Invalid strings will be rejected
let json = "\"BUNDLE\"";
let code: = from_str;
assert!;
Similar Crates
- fourcc (Deprecated?) syntax extension for rust
- four-char-code very similar to this crate, but lacks the ability to use codes in match statements