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] and Vec<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 through Deref (&*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" where GGGG and EEEE 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§

source§

impl<T> DicomJson<T>

source

pub fn into_inner(self) -> T

Unwrap the DICOM JSON wrapper, returning the underlying value.

source

pub fn inner(&self) -> &T

Obtain a reference to the underlying value.

Trait Implementations§

source§

impl<T: Clone> Clone for DicomJson<T>

source§

fn clone(&self) -> DicomJson<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug> Debug for DicomJson<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de, I> Deserialize<'de> for DicomJson<InMemDicomObject<I>>

source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<'de> Deserialize<'de> for DicomJson<Tag>

source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<'a, D> From<&'a [InMemDicomObject<D>]> for DicomJson<&'a [InMemDicomObject<D>]>

source§

fn from(value: &'a [InMemDicomObject<D>]) -> Self

Converts to this type from the input type.
source§

impl<'a, D> From<&'a DataElement<InMemDicomObject<D>>> for DicomJson<&'a InMemElement<D>>

source§

fn from(value: &'a InMemElement<D>) -> Self

Converts to this type from the input type.
source§

impl<'a, D> From<&'a FileDicomObject<InMemDicomObject<D>>> for DicomJson<&'a DefaultDicomObject<D>>

source§

fn from(value: &'a DefaultDicomObject<D>) -> Self

Converts to this type from the input type.
source§

impl<'a, D> From<&'a InMemDicomObject<D>> for DicomJson<&'a InMemDicomObject<D>>

source§

fn from(value: &'a InMemDicomObject<D>) -> Self

Converts to this type from the input type.
source§

impl<D> From<DataElement<InMemDicomObject<D>>> for DicomJson<InMemElement<D>>

source§

fn from(value: InMemElement<D>) -> Self

Converts to this type from the input type.
source§

impl<D> From<FileDicomObject<InMemDicomObject<D>>> for DicomJson<DefaultDicomObject<D>>

source§

fn from(value: DefaultDicomObject<D>) -> Self

Converts to this type from the input type.
source§

impl<D> From<InMemDicomObject<D>> for DicomJson<InMemDicomObject<D>>

source§

fn from(value: InMemDicomObject<D>) -> Self

Converts to this type from the input type.
source§

impl From<Tag> for DicomJson<Tag>

source§

fn from(value: Tag) -> Self

Converts to this type from the input type.
source§

impl<D> From<Vec<InMemDicomObject<D>>> for DicomJson<Vec<InMemDicomObject<D>>>

source§

fn from(value: Vec<InMemDicomObject<D>>) -> Self

Converts to this type from the input type.
source§

impl<T: PartialEq> PartialEq for DicomJson<T>

source§

fn eq(&self, other: &DicomJson<T>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a, D> Serialize for DicomJson<&'a [InMemDicomObject<D>]>

source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serializes the sequence of DICOM objects into a JSON array.

source§

impl<D> Serialize for DicomJson<&InMemElement<D>>

source§

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,

source§

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,

source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serializes the DICOM object as a JSON map containing one entry per data element, indexed by tag.

source§

impl<D> Serialize for DicomJson<InMemElement<D>>

source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<D> Serialize for DicomJson<DefaultDicomObject<D>>

source§

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>>

source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Serialize for DicomJson<Tag>

source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serializes the DICOM tag as a single string in uppercase hexadecimal, with no separators or delimiters ("GGGGEEEE").

source§

impl<D> Serialize for DicomJson<Vec<InMemDicomObject<D>>>

source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serializes the sequence of DICOM objects into a JSON array.

source§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,