Struct dicom_json::DicomJson
source · pub struct DicomJson<T>(/* private fields */);
Expand description
A wrapper type for DICOM JSON serialization using Serde.
Serializing this type will yield JSON data according to the standard. Deserialization from this type will interpret the input data as standard DICOM JSON deserialization.
§Serialization
Convert a DICOM data type such as a file, object, or data element
into a DicomJson
value using From
or Into
,
then use a JSON serializer such as the one in serde_json
to serialize it to the intended type.
A reference may be used as well,
so as to not consume the DICOM data.
DicomJson
can serialize:
InMemDicomObject
as a standard DICOM JSON data set;InMemElement
by writing the VR and value in a single object (note that the tag will not be serialized);&[InMemDicomObject]
andVec<InMemDicomObject>
, resulting in a JSON array of DICOM JSON data sets;DefaultDicomObject
, which will also include the attributes from the file meta group. Note however, that this is not conforming to the standard. Obtain the inner data set throughDeref
(&*obj
) if you do not wish to include file meta group data.Tag
: values are written as a single string in the expected DICOM JSON format"GGGGEEEE"
whereGGGG
andEEEE
are the group/element parts in uppercase hexadecimal.
§Example
use dicom_json::DicomJson;
// creating a DICOM object with a single attribute
let obj = InMemDicomObject::from_element_iter([
DataElement::new(
Tag(0x0010, 0x0020),
VR::LO,
PrimitiveValue::from("ID0001"),
)
]);
// wrap it with DicomJson
let json_obj = DicomJson::from(&obj);
// serialize it to a JSON Value
let serialized = serde_json::to_value(&json_obj)?;
assert_eq!(
serialized,
serde_json::json!({
"00100020": {
"vr": "LO",
"Value": [ "ID0001" ]
}
})
);
§Deserialization
Specify the concrete DICOM data type to deserialize to,
place it as the type parameter T
of DicomJson<T>
,
then request to deserialize it.
DicomJson
can deserialize:
InMemDicomObject
, expecting a JSON object indexed by tags;Tag
, a string formatted as a DICOM tag;VR
, a 2-character string with one of the supported value representation identifiers.
§Example
use dicom_json::DicomJson;
// given this JSON data
let json_data = r#"{
"00100020": {
"vr": "LO",
"Value": [ "ID0001" ]
}
}"#;
// deserialize to DicomJson, then unwrap it
let deserialized: DicomJson<InMemDicomObject> = serde_json::from_str(json_data)?;
let obj = deserialized.into_inner();
assert_eq!(
obj,
InMemDicomObject::from_element_iter([
DataElement::new(Tag(0x0010, 0x0020), VR::LO, "ID0001"),
]),
);
Implementations§
Trait Implementations§
source§impl<'de, I> Deserialize<'de> for DicomJson<InMemDicomObject<I>>
impl<'de, I> Deserialize<'de> for DicomJson<InMemDicomObject<I>>
source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
source§impl<'de> Deserialize<'de> for DicomJson<Tag>
impl<'de> Deserialize<'de> for DicomJson<Tag>
source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
source§impl<'a, D> From<&'a [InMemDicomObject<D>]> for DicomJson<&'a [InMemDicomObject<D>]>
impl<'a, D> From<&'a [InMemDicomObject<D>]> for DicomJson<&'a [InMemDicomObject<D>]>
source§fn from(value: &'a [InMemDicomObject<D>]) -> Self
fn from(value: &'a [InMemDicomObject<D>]) -> Self
source§impl<'a, D> From<&'a DataElement<InMemDicomObject<D>>> for DicomJson<&'a InMemElement<D>>
impl<'a, D> From<&'a DataElement<InMemDicomObject<D>>> for DicomJson<&'a InMemElement<D>>
source§fn from(value: &'a InMemElement<D>) -> Self
fn from(value: &'a InMemElement<D>) -> Self
source§impl<'a, D> From<&'a FileDicomObject<InMemDicomObject<D>>> for DicomJson<&'a DefaultDicomObject<D>>
impl<'a, D> From<&'a FileDicomObject<InMemDicomObject<D>>> for DicomJson<&'a DefaultDicomObject<D>>
source§fn from(value: &'a DefaultDicomObject<D>) -> Self
fn from(value: &'a DefaultDicomObject<D>) -> Self
source§impl<'a, D> From<&'a InMemDicomObject<D>> for DicomJson<&'a InMemDicomObject<D>>
impl<'a, D> From<&'a InMemDicomObject<D>> for DicomJson<&'a InMemDicomObject<D>>
source§fn from(value: &'a InMemDicomObject<D>) -> Self
fn from(value: &'a InMemDicomObject<D>) -> Self
source§impl<D> From<DataElement<InMemDicomObject<D>>> for DicomJson<InMemElement<D>>
impl<D> From<DataElement<InMemDicomObject<D>>> for DicomJson<InMemElement<D>>
source§fn from(value: InMemElement<D>) -> Self
fn from(value: InMemElement<D>) -> Self
source§impl<D> From<FileDicomObject<InMemDicomObject<D>>> for DicomJson<DefaultDicomObject<D>>
impl<D> From<FileDicomObject<InMemDicomObject<D>>> for DicomJson<DefaultDicomObject<D>>
source§fn from(value: DefaultDicomObject<D>) -> Self
fn from(value: DefaultDicomObject<D>) -> Self
source§impl<D> From<InMemDicomObject<D>> for DicomJson<InMemDicomObject<D>>
impl<D> From<InMemDicomObject<D>> for DicomJson<InMemDicomObject<D>>
source§fn from(value: InMemDicomObject<D>) -> Self
fn from(value: InMemDicomObject<D>) -> Self
source§impl<D> From<Vec<InMemDicomObject<D>>> for DicomJson<Vec<InMemDicomObject<D>>>
impl<D> From<Vec<InMemDicomObject<D>>> for DicomJson<Vec<InMemDicomObject<D>>>
source§fn from(value: Vec<InMemDicomObject<D>>) -> Self
fn from(value: Vec<InMemDicomObject<D>>) -> Self
source§impl<T: PartialEq> PartialEq for DicomJson<T>
impl<T: PartialEq> PartialEq for DicomJson<T>
source§impl<'a, D> Serialize for DicomJson<&'a [InMemDicomObject<D>]>
impl<'a, D> Serialize for DicomJson<&'a [InMemDicomObject<D>]>
source§impl<D> Serialize for DicomJson<&InMemElement<D>>
impl<D> Serialize for DicomJson<&InMemElement<D>>
source§fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>where
S: Serializer,
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>where
S: Serializer,
Serializes the data element as a single JSON map.
The fields present will be:
"vr"
, containing the value representation;- Either
"Value"
(as an array of values) or"InlineBinary"
(binary data in base64), if the value is not empty.
The DICOM tag is not encoded, as it is typically serialized as the entry key within a data set.
source§impl<'a, D> Serialize for DicomJson<&'a DefaultDicomObject<D>>where
D: 'a,
impl<'a, D> Serialize for DicomJson<&'a DefaultDicomObject<D>>where
D: 'a,
source§fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>where
S: Serializer,
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>where
S: Serializer,
Serializes the DICOM file as a JSON map containing one entry per data element (indexed by tag), plus the data elements described by its file meta table.
To exclude the file meta group data instead,
dereference the value into the underlying DICOM object first
(e.g. via &*obj
).
source§impl<'a, D> Serialize for DicomJson<&'a InMemDicomObject<D>>where
D: 'a,
impl<'a, D> Serialize for DicomJson<&'a InMemDicomObject<D>>where
D: 'a,
source§impl<D> Serialize for DicomJson<InMemElement<D>>
impl<D> Serialize for DicomJson<InMemElement<D>>
source§impl<D> Serialize for DicomJson<DefaultDicomObject<D>>
impl<D> Serialize for DicomJson<DefaultDicomObject<D>>
source§fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>where
S: Serializer,
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>where
S: Serializer,
Serializes the DICOM file as a JSON map containing one entry per data element (indexed by tag), plus the data elements described by its file meta table.
To exclude the file meta group data instead,
dereference the value into the underlying DICOM object first
(e.g. via &*obj
).
source§impl<D> Serialize for DicomJson<InMemDicomObject<D>>
impl<D> Serialize for DicomJson<InMemDicomObject<D>>
impl<T> StructuralPartialEq for DicomJson<T>
Auto Trait Implementations§
impl<T> Freeze for DicomJson<T>where
T: Freeze,
impl<T> RefUnwindSafe for DicomJson<T>where
T: RefUnwindSafe,
impl<T> Send for DicomJson<T>where
T: Send,
impl<T> Sync for DicomJson<T>where
T: Sync,
impl<T> Unpin for DicomJson<T>where
T: Unpin,
impl<T> UnwindSafe for DicomJson<T>where
T: UnwindSafe,
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> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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