Newtype wrapper providing a convenient representation of four-character-code values.
Using this type in a public APIs as an alternative to simply passing the equivalent u32
makes the value's expected use explicit.
Creating a FourCC value
use FourCC;
let uuid = FourCC;
From a slice
# use FourCC;
let data = b"moofftyp";
let code = from; // would panic if fewer than 4 bytes
assert_eq!;
Constants
FourCC values can be used in const expressions
# use FourCC;
const UUID: FourCC = FourCC;
Matching
You can use FourCC values in match patterns as long as you define constants to match against,
# use FourCC;
const UUID: FourCC = FourCC;
const MOOV: FourCC = FourCC;
# let other_value = UUID;
match other_value
Invalid literal values
If the literal has other than four bytes, compilation will fail
# use four_cc::FourCC;
let bad_fourcc = FourCC(*b"uuid123");
// -> expected an array with a fixed size of 4 elements, found one with 7 elements
Note the FourCC value may contain non-printable byte values, including the byte-value zero.
Debug display
# use FourCC;
# use Debug;
let uuid = FourCC;
# assert_eq!;
println!; // produces: it's FourCC{uuid}
Note that if the FourCC bytes are not able to be converted to UTF8, then a fallback
representation will be used (as it would be suprising for format!() to panic).
# use FourCC;
# use Debug;
let uuid = FourCC;
# assert_eq!;
println!; // produces: it's FourCC{u\xffi\x00}