Skip to content

Commit

Permalink
[object] Reiterate on DicomObject
Browse files Browse the repository at this point in the history
- replace `to_dicom_value` with `to_primitive_value`
   - simplifies implementations
   and requires consumers to
   depend on other methods
   when working with sequences
- remove method `meta`
   - treat meta information attributes like any other attribute,
   retrievable through the same methods
- [core] add either crate
- impl many DICOM traits to `either::Either`
- implement DicomObject for FileMetaTable
- reimplement DICOM traits for FileDicomObject
  so that users can retrieve
  either meta info or main data set info
  • Loading branch information
Enet4 committed Jun 29, 2024
1 parent 53bd0b2 commit c757898
Show file tree
Hide file tree
Showing 5 changed files with 569 additions and 52 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ readme = "README.md"

[dependencies]
chrono = { version = "0.4.31", default-features = false, features = ["std", "clock"] }
either = "1.13.0"
itertools = "0.12"
num-traits = "0.2.12"
safe-transmute = "0.11.0"
Expand Down
35 changes: 35 additions & 0 deletions core/src/value/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ pub use self::primitive::{
ValueType,
};

pub use either::Either;

/// An aggregation of one or more elements in a value.
pub type C<T> = SmallVec<[T; 2]>;

Expand All @@ -43,6 +45,39 @@ pub trait DicomValueType: HasLength {
fn cardinality(&self) -> usize;
}

impl<L, R> HasLength for Either<L, R>
where
L: HasLength,
R: HasLength,
{
fn length(&self) -> Length {
match self {
Either::Left(l) => l.length(),
Either::Right(r) => r.length(),
}
}
}

impl<L, R> DicomValueType for Either<L, R>
where
L: DicomValueType,
R: DicomValueType,
{
fn value_type(&self) -> ValueType {
match self {
Either::Left(l) => l.value_type(),
Either::Right(r) => r.value_type(),
}
}

fn cardinality(&self) -> usize {
match self {
Either::Left(l) => l.cardinality(),
Either::Right(r) => r.cardinality(),
}
}
}

/// Representation of a full DICOM value, which may be either primitive or
/// another DICOM object.
///
Expand Down
Loading

0 comments on commit c757898

Please sign in to comment.