46 lines
833 B
Rust
46 lines
833 B
Rust
//! Library for various utilities.
|
|
|
|
#[allow(dead_code)]
|
|
pub mod bin;
|
|
pub mod chunk;
|
|
pub mod crc;
|
|
pub mod err;
|
|
pub mod fx32;
|
|
pub mod image;
|
|
pub mod machead;
|
|
pub mod text;
|
|
|
|
/// Creates an enumeration and function for converting a representation into
|
|
/// the enumeration type.
|
|
#[macro_export]
|
|
macro_rules! c_enum
|
|
{
|
|
(
|
|
$(#[$outer:meta])*
|
|
pub enum $E:ident: $T:ty
|
|
{
|
|
$($value:expr => $Enum:ident,)+
|
|
}
|
|
) => {
|
|
$(#[$outer])*
|
|
pub enum $E
|
|
{
|
|
$($Enum,)+
|
|
}
|
|
|
|
impl $E
|
|
{
|
|
pub fn from_repr(n: $T) -> ResultS<$E>
|
|
{
|
|
let t = match n {
|
|
$($value => $E::$Enum,)+
|
|
n => return Err(format_err!("invalid representation for {} (got {})", stringify!($E), n))
|
|
};
|
|
Ok(t)
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
// EOF
|