pub trait DicomObject {
type Attribute<'a>: DicomAttribute
where Self: 'a;
type LeafAttribute<'a>: DicomAttribute
where Self: 'a;
// Required methods
fn attr_opt(
&self,
tag: Tag,
) -> Result<Option<Self::Attribute<'_>>, AccessError>;
fn attr_by_name_opt(
&self,
name: &str,
) -> Result<Option<Self::Attribute<'_>>, AccessByNameError>;
fn at(
&self,
selector: impl Into<AttributeSelector>,
) -> Result<Self::LeafAttribute<'_>, AtAccessError>;
// Provided methods
fn attr(&self, tag: Tag) -> Result<Self::Attribute<'_>, AccessError> { ... }
fn attr_by_name(
&self,
name: &str,
) -> Result<Self::Attribute<'_>, AccessByNameError> { ... }
}Expand description
Trait type for a generalized interpretation of a DICOM object.
This is a high-level abstraction where an object is accessed and manipulated as a dictionary of entries indexed by tags, which in turn may contain a DICOM object.
§Examples
You can use this trait to operate on DICOM data sets when the exact DICOM object type is not known.
use dicom_object::DicomObject;
use dicom_object::DicomAttribute as _;
fn my_data() -> impl DicomObject {
InMemDicomObject::from_element_iter([
DataElement::new(
tags::SOP_INSTANCE_UID,
VR::UI,
"2.25.60131396312732822704775296119377475501",
),
])
}
let obj = my_data();
assert_eq!(
obj.attr(tags::SOP_INSTANCE_UID)?.to_str()?,
"2.25.60131396312732822704775296119377475501"
);It works for in-memory data sets, file meta groups, and other similar structures. When operating on DICOM file objects, the look-up will be directed to the right group depending on the attribute requested.
use dicom_object::{DicomObject as _, open_file};
let file = open_file("00001.dcm")?;
let Some(media_storage_sop_class_uid) = file.attr_opt(tags::MEDIA_STORAGE_SOP_CLASS_UID)? else {
panic!("DICOM file should have a Media Storage SOP Class UID");
};Types implementing this trait
will likely also implement ApplyOp,
enabling more operations on DICOM objects.
Required Associated Types§
Sourcetype Attribute<'a>: DicomAttribute
where
Self: 'a
type Attribute<'a>: DicomAttribute where Self: 'a
Sourcetype LeafAttribute<'a>: DicomAttribute
where
Self: 'a
type LeafAttribute<'a>: DicomAttribute where Self: 'a
The type representing a DICOM leaf attribute in the object and/or the necessary means to retrieve the value from it.
This is the outcome of a potentially deep look-up
using the method at.
Required Methods§
Sourcefn attr_opt(&self, tag: Tag) -> Result<Option<Self::Attribute<'_>>, AccessError>
fn attr_opt(&self, tag: Tag) -> Result<Option<Self::Attribute<'_>>, AccessError>
Retrieve a particular DICOM attribute by looking up the given tag at the object’s root.
Ok(None) is returned when the object was successfully looked up
but the element is not present.
This is not a recursive search.
Sourcefn attr_by_name_opt(
&self,
name: &str,
) -> Result<Option<Self::Attribute<'_>>, AccessByNameError>
fn attr_by_name_opt( &self, name: &str, ) -> Result<Option<Self::Attribute<'_>>, AccessByNameError>
Retrieve a particular DICOM element by its name (keyword).
Ok(None) is returned when the object was successfully looked up
but the element is not present.
If the DICOM tag is already known,
prefer calling attr_opt
with one of the constants from the DICOM dictionary.
Sourcefn at(
&self,
selector: impl Into<AttributeSelector>,
) -> Result<Self::LeafAttribute<'_>, AtAccessError>
fn at( &self, selector: impl Into<AttributeSelector>, ) -> Result<Self::LeafAttribute<'_>, AtAccessError>
Retrieve a particular DICOM attribute with a look-up by attribute selector.
This method returns an error if the element is not present.
Provided Methods§
Sourcefn attr(&self, tag: Tag) -> Result<Self::Attribute<'_>, AccessError>
fn attr(&self, tag: Tag) -> Result<Self::Attribute<'_>, AccessError>
Retrieve a particular DICOM attribute by looking up the given tag at the object’s root.
Unlike attr_opt,
this method returns an error if the element is not present.
Sourcefn attr_by_name(
&self,
name: &str,
) -> Result<Self::Attribute<'_>, AccessByNameError>
fn attr_by_name( &self, name: &str, ) -> Result<Self::Attribute<'_>, AccessByNameError>
Retrieve a particular DICOM element by its name (keyword).
Unlike attr_by_name_opt,
this method returns an error if the element is not present.
If the DICOM tag is already known,
prefer calling attr
with one of the constants from the DICOM dictionary.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.