#![crate_type = "lib"]
#![deny(trivial_numeric_casts, unsafe_code, unstable_features)]
#![warn(
missing_debug_implementations,
unused_qualifications,
unused_import_braces
)]
#![allow(clippy::derive_partial_eq_without_eq)]
pub mod dictionary;
pub mod header;
pub mod value;
pub use dictionary::DataDictionary;
pub use header::{DataElement, DataElementHeader, Length, Tag, VR};
pub use value::{PrimitiveValue, Value as DicomValue};
pub use chrono;
pub use smallvec;
mod util;
#[macro_export]
macro_rules! dicom_value {
() => { $crate::value::PrimitiveValue::Empty };
(Strs, [ $($elem: expr),+ , ]) => {
{
use smallvec::smallvec; $crate::value::PrimitiveValue :: Strs (smallvec![$($elem.to_owned(),)*])
}
};
(Strs, [ $($elem: expr),+ ]) => {
{
use smallvec::smallvec; $crate::value::PrimitiveValue :: Strs (smallvec![$($elem.to_owned(),)*])
}
};
($typ: ident, [ $($elem: expr),+ , ]) => {
{
use smallvec::smallvec; $crate::value::PrimitiveValue :: $typ (smallvec![$($elem,)*])
}
};
($typ: ident, [ $($elem: expr),+ ]) => {
{
use smallvec::smallvec; $crate::value::PrimitiveValue :: $typ (smallvec![$($elem,)*])
}
};
(Str, $elem: expr) => {
$crate::value::PrimitiveValue :: Str (String::from($elem))
};
($typ: ident, $elem: expr) => {
$crate::value::PrimitiveValue :: $typ ($crate::value::C::from_elem($elem, 1))
};
($elem: expr) => {
$crate::value::PrimitiveValue::from($elem)
};
}
#[cfg(test)]
mod tests {
use crate::dicom_value;
use crate::value::PrimitiveValue;
use smallvec::smallvec;
#[test]
fn macro_dicom_value() {
assert_eq!(
dicom_value!(Str, "PALETTE COLOR "),
PrimitiveValue::Str("PALETTE COLOR ".to_owned()),
);
assert_eq!(
dicom_value!("PALETTE COLOR "),
PrimitiveValue::Str("PALETTE COLOR ".to_owned()),
);
assert_eq!(
dicom_value!(Strs, ["BASE", "LIGHT", "DARK"]),
PrimitiveValue::Strs(smallvec![
"BASE".to_owned(),
"LIGHT".to_owned(),
"DARK".to_owned(),
]),
);
assert_eq!(
dicom_value!(
Strs,
[
"DERIVED",
"PRIMARY".to_string(), "WHOLE BODY",
"EMISSION"
]
),
PrimitiveValue::Strs(smallvec![
"DERIVED".to_string(),
"PRIMARY".to_string(),
"WHOLE BODY".to_string(),
"EMISSION".to_string(),
]),
);
assert_eq!(
dicom_value!(Strs, ["DERIVED", "PRIMARY", "WHOLE BODY", "EMISSION",]),
PrimitiveValue::Strs(smallvec![
"DERIVED".to_string(),
"PRIMARY".to_string(),
"WHOLE BODY".to_string(),
"EMISSION".to_string(),
]),
);
assert_eq!(dicom_value!(U16, 55), PrimitiveValue::U16(smallvec![55]),);
assert_eq!(dicom_value!(55_u32), PrimitiveValue::U32(smallvec![55]),);
assert_eq!(
dicom_value!(I32, [11, 22, 33]),
PrimitiveValue::I32(smallvec![11, 22, 33]),
);
assert_eq!(dicom_value!(), PrimitiveValue::Empty,);
}
}