Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix using dicom_value! without smallvec import #366

Merged
merged 6 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 4 additions & 16 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,28 +120,16 @@ macro_rules! dicom_value {
() => { $crate::value::PrimitiveValue::Empty };
// Multiple strings
(Strs, [ $($elem: expr),+ , ]) => {
{
use smallvec::smallvec; // import smallvec macro
$crate::value::PrimitiveValue :: Strs (smallvec![$($elem.to_owned(),)*])
}
$crate::value::PrimitiveValue :: Strs ($crate::smallvec::smallvec![$($elem.to_owned(),)*])
};
(Strs, [ $($elem: expr),+ ]) => {
{
use smallvec::smallvec; // import smallvec macro
$crate::value::PrimitiveValue :: Strs (smallvec![$($elem.to_owned(),)*])
}
$crate::value::PrimitiveValue :: Strs ($crate::smallvec::smallvec![$($elem.to_owned(),)*])
};
($typ: ident, [ $($elem: expr),+ , ]) => {
{
use smallvec::smallvec; // import smallvec macro
$crate::value::PrimitiveValue :: $typ (smallvec![$($elem,)*])
}
$crate::value::PrimitiveValue :: $typ ($crate::smallvec::smallvec![$($elem,)*])
};
($typ: ident, [ $($elem: expr),+ ]) => {
{
use smallvec::smallvec; // import smallvec macro
$crate::value::PrimitiveValue :: $typ (smallvec![$($elem,)*])
}
$crate::value::PrimitiveValue :: $typ ($crate::smallvec::smallvec![$($elem,)*])
};
(Str, $elem: expr) => {
$crate::value::PrimitiveValue :: Str (String::from($elem))
Expand Down
27 changes: 27 additions & 0 deletions core/tests/dicom_value.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//! Separate test suite for using `dicom_value!` in an isolated context,
//! without direct access to dependency `smallvec`

// empty module makes `smallvec` dependency unreachable,
// as would be typical in dependents of `dicom_core`
// unless they include it themselves
mod smallvec {}

#[test]
fn use_dicom_value() {
use dicom_core::dicom_value;

// multiple string literals with variant, no trailing comma
let value = dicom_value!(Strs, ["BASE", "LIGHT", "DARK"]);
assert_eq!(
value.to_multi_str().as_ref(),
&["BASE".to_owned(), "LIGHT".to_owned(), "DARK".to_owned(),],
);

// single string with variant
let value = dicom_value!(Str, "PALETTE COLOR ");
assert_eq!(value.to_string(), "PALETTE COLOR",);

// numeric values
let value = dicom_value!(U16, [1, 2, 5]);
assert_eq!(value.to_multi_int::<u16>().unwrap(), &[1, 2, 5],);
}
1 change: 0 additions & 1 deletion echoscu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ dicom-dictionary-std = { path = "../dictionary-std/", version = "0.5.0" }
dicom-object = { path = "../object/", version = "0.5.3" }
dicom-transfer-syntax-registry = { path = "../transfer-syntax-registry/", version = "0.5.1", default-features = false }
dicom-ul = { path = "../ul", version = "0.4.3" }
smallvec = "1.6.1"
snafu = "0.7.3"
tracing = "0.1.34"
tracing-subscriber = "0.3.11"
3 changes: 1 addition & 2 deletions findscu/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use clap::Parser;
use dicom_core::{dicom_value, smallvec};
use dicom_core::dicom_value;
use dicom_core::{DataElement, PrimitiveValue, VR};
use dicom_dictionary_std::tags;
use dicom_dump::DumpOptions;
Expand All @@ -12,7 +12,6 @@ use dicom_ul::{
pdu::{PDataValue, PDataValueType},
};
use query::parse_queries;
use smallvec::smallvec;
use snafu::prelude::*;
use std::io::{stderr, Read};
use std::path::PathBuf;
Expand Down
1 change: 0 additions & 1 deletion storescp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ dicom-object = { path = '../object', version = "0.5.4" }
dicom-encoding = { path = "../encoding/", version = "0.5.3" }
dicom-dictionary-std = { path = "../dictionary-std/", version = "0.5.0" }
dicom-transfer-syntax-registry = { path = "../transfer-syntax-registry/", version = "0.5.1" }
smallvec = "1.6.1"
snafu = "0.7.3"
tracing = "0.1.36"
tracing-subscriber = "0.3.15"
3 changes: 1 addition & 2 deletions storescu/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use clap::Parser;
use dicom_core::{dicom_value, header::Tag, smallvec, DataElement, PrimitiveValue, VR};
use dicom_core::{dicom_value, header::Tag, DataElement, PrimitiveValue, VR};
use dicom_dictionary_std::tags;
use dicom_encoding::transfer_syntax;
use dicom_object::{mem::InMemDicomObject, open_file, StandardDataDictionary};
Expand All @@ -9,7 +9,6 @@ use dicom_ul::{
pdu::{PDataValue, PDataValueType, Pdu},
};
use indicatif::{ProgressBar, ProgressStyle};
use smallvec::smallvec;
use snafu::prelude::*;
use snafu::{Report, Whatever};
use std::collections::HashSet;
Expand Down