pub struct AttributeSelector(/* private fields */);
Expand description
An attribute selector.
This type defines the path to an element in a DICOM data set, even at an arbitrary depth of nested data sets. A selector may be perceived as a series of navigation steps to reach a certain data element, where all steps but the last one refer to data set sequences.
Attribute selectors can be created through
one of the various From
conversions,
the dynamic constructor function new
,
or through parsing.
§Syntax
A syntax is defined for the unambiguous conversion
between a string and an AttributeSelector
value,
in both directions.
Attribute selectors are defined by the syntax
( «key»([«item»])? . )* «key»
where:
«key»
is either a DICOM tag in a supported textual form, or a tag keyword as accepted by the data dictionary in use;«item»
is an unsigned integer representing the item index, which is always surrounded by square brackets in the input;[
,]
, and.
are literally their own characters as part of the input.
The first part in parentheses may appear zero or more times.
The [«item»]
part can be omitted,
in which case it is assumed that the first item is selected.
Whitespace is not admitted in any position.
Displaying a selector through the Display
trait
produces a string that is compliant with this syntax.
§Examples of attribute selectors in text:
(0002,00010)
: selects Transfer Syntax UID00101010
: selects Patient Age0040A168[0].CodeValue
: selects Code Value within the first item of Concept Code Sequence0040,A730[1].ContentSequence
: selects Content Sequence in second item of Content SequenceSequenceOfUltrasoundRegions.RegionSpatialFormat
: Region Spatial Format in first item of Sequence of Ultrasound Regions
§Example
In most cases, you might only wish to select an attribute
that is sitting at the root of the data set.
This can be done by converting a DICOM tag via From<Tag>
:
// select Patient Name
let selector = AttributeSelector::from(Tag(0x0010, 0x0010));
For working with nested data sets,
From
also supports converting
an interleaved sequence of tags and item indices in a tuple.
For instance,
this is how we can select the second frame’s acquisition date time
from the per-frame functional groups sequence.
let selector: AttributeSelector = (
// Per-frame functional groups sequence
Tag(0x5200, 0x9230),
// item #1
1,
// Frame Acquisition Date Time (DT)
Tag(0x0018, 0x9074)
).into();
For a more dynamic construction,
the new
function supports an iterator of attribute selector steps
(of type AttributeSelectorStep
).
Note that the function fails
if the last step refers to a sequence item.
let selector = AttributeSelector::new([
// Per-frame functional groups sequence, item #1
AttributeSelectorStep::Nested {
tag: Tag(0x5200, 0x9230),
// item #1
item: 1,
},
// Frame Acquisition Date Time
AttributeSelectorStep::Tag(Tag(0x0018, 0x9074)),
]).ok_or_else(|| "should be a valid sequence")?;
A data dictionary’s parse_selector
method
can be used if you want to describe these selectors in text.
use dicom_core::dictionary::DataDictionary;
use dicom_dictionary_std::StandardDataDictionary;
assert_eq!(
StandardDataDictionary.parse_selector(
"PerFrameFunctionalGroupsSequence[1].(0018,9074)"
)?,
AttributeSelector::from((
// Per-frame functional groups sequence
Tag(0x5200, 0x9230),
// item #1
1,
// Frame Acquisition Date Time (DT)
Tag(0x0018, 0x9074)
)),
);
Selectors can be decomposed back into its constituent steps by turning it into an iterator:
let steps: Vec<AttributeSelectorStep> = selector.into_iter().collect();
assert_eq!(
&steps,
&[
AttributeSelectorStep::Nested {
tag: Tag(0x5200, 0x9230),
item: 1,
},
AttributeSelectorStep::Tag(Tag(0x0018, 0x9074)),
],
);
Implementations§
Source§impl AttributeSelector
impl AttributeSelector
Sourcepub fn new(
steps: impl IntoIterator<Item = AttributeSelectorStep>,
) -> Option<Self>
pub fn new( steps: impl IntoIterator<Item = AttributeSelectorStep>, ) -> Option<Self>
Construct an attribute selector from an arbitrary sequence of selector steps.
Intermediate steps of variant Tag
(which do not specify an item index)
are automatically reinterpreted as item selectors for item index 0.
Returns None
if the sequence is empty
or the last step is not a tag selector step.
Sourcepub fn iter(&self) -> impl Iterator<Item = &AttributeSelectorStep>
pub fn iter(&self) -> impl Iterator<Item = &AttributeSelectorStep>
Sourcepub fn first_step(&self) -> &AttributeSelectorStep
pub fn first_step(&self) -> &AttributeSelectorStep
Obtain a reference to the first attribute selection step.
Sourcepub fn last_step(&self) -> &AttributeSelectorStep
pub fn last_step(&self) -> &AttributeSelectorStep
Obtain a reference to the last attribute selection step.
Trait Implementations§
Source§impl Clone for AttributeSelector
impl Clone for AttributeSelector
Source§fn clone(&self) -> AttributeSelector
fn clone(&self) -> AttributeSelector
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for AttributeSelector
impl Debug for AttributeSelector
Source§impl Display for AttributeSelector
impl Display for AttributeSelector
Source§impl From<(Tag, Tag)> for AttributeSelector
impl From<(Tag, Tag)> for AttributeSelector
Creates an attribute selector for tag.tag
(where the first)
Source§impl From<(Tag, Tag, Tag)> for AttributeSelector
impl From<(Tag, Tag, Tag)> for AttributeSelector
Creates an attribute selector for tag.tag.tag
Source§impl From<(Tag, Tag, u32, Tag)> for AttributeSelector
impl From<(Tag, Tag, u32, Tag)> for AttributeSelector
Creates an attribute selector for tag.tag[item].tag
Source§impl From<(Tag, u32, Tag)> for AttributeSelector
impl From<(Tag, u32, Tag)> for AttributeSelector
Creates an attribute selector for tag[item].tag
Source§impl From<(Tag, u32, Tag, Tag)> for AttributeSelector
impl From<(Tag, u32, Tag, Tag)> for AttributeSelector
Creates an attribute selector for tag[item].tag.tag
Source§impl From<(Tag, u32, Tag, u32, Tag)> for AttributeSelector
impl From<(Tag, u32, Tag, u32, Tag)> for AttributeSelector
Creates an attribute selector for tag[item].tag[item].tag
Source§impl From<(Tag, u32, Tag, u32, Tag, u32, Tag)> for AttributeSelector
impl From<(Tag, u32, Tag, u32, Tag, u32, Tag)> for AttributeSelector
Creates an attribute selector for tag[item].tag[item].tag[item].tag
Source§impl Hash for AttributeSelector
impl Hash for AttributeSelector
Source§impl<'a> IntoIterator for &'a AttributeSelector
impl<'a> IntoIterator for &'a AttributeSelector
Source§impl IntoIterator for AttributeSelector
impl IntoIterator for AttributeSelector
Source§impl PartialEq for AttributeSelector
impl PartialEq for AttributeSelector
impl Eq for AttributeSelector
impl StructuralPartialEq for AttributeSelector
Auto Trait Implementations§
impl Freeze for AttributeSelector
impl RefUnwindSafe for AttributeSelector
impl Send for AttributeSelector
impl Sync for AttributeSelector
impl Unpin for AttributeSelector
impl UnwindSafe for AttributeSelector
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more