Skip to content

Commit 5486de4

Browse files
committed
Add EmptyObject
Zero type enables representing DICOM values not containing objects
1 parent e22ad40 commit 5486de4

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

core/src/header.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! element header, and element composite types.
44
55
use crate::error::{Error, Result};
6-
use crate::value::{DicomValueType, PrimitiveValue, Value};
6+
use crate::value::{PrimitiveValue, Value};
77
use std::borrow::Cow;
88
use std::cmp::Ordering;
99
use std::fmt;
@@ -46,9 +46,23 @@ pub trait Header: HasLength {
4646
}
4747
}
4848

49+
/// Stub type representing a non-existing DICOM object.
50+
///
51+
/// This type implements `HasLength`, but cannot be instantiated.
52+
/// This makes it so that `Value<EmptyObject>` is sure to be either a primitive
53+
/// value or a sequence with no items.
54+
#[derive(Debug, PartialEq)]
55+
pub enum EmptyObject {}
56+
57+
impl HasLength for EmptyObject {
58+
fn length(&self) -> Length {
59+
unreachable!()
60+
}
61+
}
62+
4963
/// A data type that represents and owns a DICOM data element. Unlike
5064
/// [`PrimitiveDataElement`], this type may contain multiple data elements
51-
/// through the item sequence VR (of type `I`).
65+
/// through the item sequence VR (where each item contains an object of type `I`).
5266
#[derive(Debug, PartialEq, Clone)]
5367
pub struct DataElement<I> {
5468
header: DataElementHeader,

parser/src/dataset/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@ pub trait IntoTokens {
110110
fn into_tokens(self) -> Self::Iter;
111111
}
112112

113+
impl IntoTokens for dicom_core::header::EmptyObject {
114+
type Iter = std::iter::Empty<DataToken>;
115+
116+
fn into_tokens(self) -> Self::Iter {
117+
unreachable!()
118+
}
119+
}
120+
113121
/// Token generator from a DICOM data element.
114122
pub enum DataElementTokens<I>
115123
where

0 commit comments

Comments
 (0)