#extension #syntax #generate #macro #plugin #four-character

nightly fourcc

Syntax extension to generate FourCCs (four-character code)

4 releases

Uses old Rust 2015

0.0.4 Sep 18, 2015
0.0.3 Mar 25, 2015
0.0.2 Nov 21, 2014
0.0.1 Nov 20, 2014

#235 in #syntax

MIT/Apache

7KB
99 lines

fourcc

A Rust syntax extension to generate FourCCs.

Build Status

Usage

Add this to your Cargo.toml:

[dependencies]

fourcc = "*"

and this to your crate root:

#![feature(plugin)]
#![plugin(fourcc)]

lib.rs:

Syntax extension to generate FourCCs.

Once loaded, fourcc!() is called with a single 4-character string, and an optional ident that is either big, little, or target. The ident represents endianness, and specifies in which direction the characters should be read. If the ident is omitted, it is assumed to be big, i.e. left-to-right order. It returns a u32.

Examples

To load the extension and use it:

#[phase(plugin)]
extern crate fourcc;

fn main() {
    let val = fourcc!("\xC0\xFF\xEE!");
    assert_eq!(val, 0xC0FFEE21u32);
    let little_val = fourcc!("foo ", little);
    assert_eq!(little_val, 0x21EEFFC0u32);
}

References

No runtime deps