dicom_core::value

Enum Value

Source
pub enum Value<I = EmptyObject, P = InMemFragment> {
    Primitive(PrimitiveValue),
    Sequence(DataSetSequence<I>),
    PixelSequence(PixelFragmentSequence<P>),
}
Expand description

Representation of a full DICOM value, which may be either primitive or another DICOM object.

I is the complex type for nest data set items, which should usually implement HasLength. P is the encapsulated pixel data provider, which should usually implement AsRef<[u8]>.

Variants§

§

Primitive(PrimitiveValue)

Primitive value.

§

Sequence(DataSetSequence<I>)

A complex sequence of items.

§

PixelSequence(PixelFragmentSequence<P>)

A sequence of encapsulated pixel data fragments.

Implementations§

Source§

impl<P> Value<EmptyObject, P>

Source

pub fn new_pixel_sequence<T>(offset_table: C<u32>, fragments: T) -> Self
where T: Into<C<P>>,

Construct an isolated DICOM pixel sequence sequence value from a basic offset table and a list of fragments.

This function will define the data set sequence item type I to an empty object (EmptyObject), so that it can be used more easily in isolation. As a consequence, it cannot be directly combined with DICOM objects that may contain sequence values. To let the type parameter I be inferred from its context, create a PixelFragmentSequence and use Value::from instead.

Note: This function does not validate the offset table against the fragments.

Source§

impl<I> Value<I>

Source

pub fn new_sequence<T>(items: T, length: Length) -> Self
where T: Into<C<I>>,

Construct an isolated DICOM data set sequence value from a list of items and length.

This function will define the pixel data fragment type parameter P to the Value type’s default (InMemFragment), so that it can be used more easily. If necessary, it is possible to let this type parameter be inferred from its context by creating a DataSetSequence and using Value::from instead.

Source§

impl Value

Source

pub fn new(value: PrimitiveValue) -> Self

Construct a DICOM value from a primitive value.

This is equivalent to Value::from in behavior, except that suitable type parameters are specified instead of inferred.

This function will automatically define the sequence item parameter I to EmptyObject and the pixel data fragment type parameter P to the default fragment data type (InMemFragment), so that it can be used more easily in isolation. As a consequence, it cannot be directly combined with DICOM objects that may contain nested data sets or encapsulated pixel data. To let the type parameters I and P be inferred from their context, create a value of one of the types and use Value::from instead.

Source§

impl<I, P> Value<I, P>

Source

pub fn multiplicity(&self) -> u32

Obtain the number of individual values. In a primitive, this is the number of individual elements in the value. In a sequence item, this is the number of items. In a pixel sequence, this is currently set to 1 regardless of the number of compressed fragments or frames.

Source

pub fn primitive(&self) -> Option<&PrimitiveValue>

Gets a reference to the primitive value.

Source

pub fn primitive_mut(&mut self) -> Option<&mut PrimitiveValue>

Gets a mutable reference to the primitive value.

Source

pub fn items(&self) -> Option<&[I]>

Gets a reference to the items of a sequence.

Returns None if the value is not a data set sequence.

Source

pub fn items_mut(&mut self) -> Option<&mut C<I>>

Gets a mutable reference to the items of a sequence.

Returns None if the value is not a data set sequence.

Source

pub fn fragments(&self) -> Option<&[P]>

Gets a reference to the fragments of a pixel data sequence.

Returns None if the value is not a pixel data sequence.

Source

pub fn fragments_mut(&mut self) -> Option<&mut C<P>>

Gets a mutable reference to the fragments of a pixel data sequence.

Returns None if the value is not a pixel data sequence.

Source

pub fn into_primitive(self) -> Option<PrimitiveValue>

Retrieves the primitive value.

Source

pub fn into_items(self) -> Option<C<I>>

Retrieves the data set items, discarding the recorded length information.

Returns None if the value is not a data set sequence.

Source

pub fn into_fragments(self) -> Option<C<P>>

Retrieves the pixel data fragments, discarding the rest of the information.

Source

pub fn offset_table(&self) -> Option<&[u32]>

Gets a reference to the encapsulated pixel data’s offset table.

Returns None if the value is not a pixel data sequence.

Source

pub fn offset_table_mut(&mut self) -> Option<&mut C<u32>>

Gets a mutable reference to the encapsulated pixel data’s offset table.

Returns None if the value is not a pixel data sequence.

Source

pub fn truncate(&mut self, limit: usize)

Shorten this value by removing trailing elements to fit the given limit.

On primitive values, elements are counted by the number of individual value items (note that bytes in a PrimitiveValue::U8 are treated as individual items). On data set sequences and pixel data fragment sequences, this operation is applied to the data set items (or fragments) in the sequence.

Nothing is done if the value’s cardinality is already lower than or equal to the limit.

Source§

impl<I, P> Value<I, P>
where I: HasLength,

Source

pub fn to_str(&self) -> Result<Cow<'_, str>, ConvertValueError>

Convert the full primitive value into a clean string.

The value is converted into a strings as described in PrimitiveValue::to_str. If the value contains multiple strings, they are trimmed at the end and concatenated (separated by the standard DICOM value delimiter '\\') into an owned string.

Returns an error if the value is not primitive.

Source

pub fn to_raw_str(&self) -> Result<Cow<'_, str>, ConvertValueError>

Convert the full primitive value into a single raw string, with trailing whitespace kept.

If the value contains multiple strings, they are concatenated (separated by the standard DICOM value delimiter '\\') into an owned string.

Returns an error if the value is not primitive.

Source

pub fn to_multi_str(&self) -> Result<Cow<'_, [String]>, CastValueError>

Convert the full primitive value into a sequence of strings.

If the value is a primitive, it will be converted into a vector of strings as described in PrimitiveValue::to_multi_str.

Returns an error if the value is not primitive.

Source

pub fn to_bytes(&self) -> Result<Cow<'_, [u8]>, ConvertValueError>

Convert the full primitive value into raw bytes.

String values already encoded with the Str and Strs variants are provided in UTF-8.

Returns an error if the value is not primitive.

Source

pub fn to_int<T>(&self) -> Result<T, ConvertValueError>
where T: Clone + NumCast + FromStr<Err = ParseIntError>,

Retrieve and convert the primitive value into an integer.

If the value is a primitive, it will be converted into an integer as described in PrimitiveValue::to_int.

Source

pub fn to_multi_int<T>(&self) -> Result<Vec<T>, ConvertValueError>
where T: Clone + NumCast + FromStr<Err = ParseIntError>,

Retrieve and convert the primitive value into a sequence of integers.

If the value is a primitive, it will be converted into a vector of integers as described in PrimitiveValue::to_multi_int.

Source

pub fn to_float32(&self) -> Result<f32, ConvertValueError>

Retrieve and convert the primitive value into a single-precision floating point number.

If the value is a primitive, it will be converted into a number as described in PrimitiveValue::to_float32.

Source

pub fn to_multi_float32(&self) -> Result<Vec<f32>, ConvertValueError>

Retrieve and convert the primitive value into a sequence of single-precision floating point numbers.

If the value is a primitive, it will be converted into a vector of numbers as described in PrimitiveValue::to_multi_float32.

Source

pub fn to_float64(&self) -> Result<f64, ConvertValueError>

Retrieve and convert the primitive value into a double-precision floating point number.

If the value is a primitive, it will be converted into a number as described in PrimitiveValue::to_float64.

Source

pub fn to_multi_float64(&self) -> Result<Vec<f64>, ConvertValueError>

Retrieve and convert the primitive value into a sequence of double-precision floating point numbers.

If the value is a primitive, it will be converted into a vector of numbers as described in PrimitiveValue::to_multi_float64.

Source

pub fn to_date(&self) -> Result<DicomDate, ConvertValueError>

Retrieve and convert the primitive value into a DicomDate.

If the value is a primitive, it will be converted into a DicomDate as described in PrimitiveValue::to_date.

Source

pub fn to_multi_date(&self) -> Result<Vec<DicomDate>, ConvertValueError>

Retrieve and convert the primitive value into a sequence of DicomDates.

If the value is a primitive, it will be converted into a vector of DicomDate as described in PrimitiveValue::to_multi_date.

Source

pub fn to_time(&self) -> Result<DicomTime, ConvertValueError>

Retrieve and convert the primitive value into a DicomTime.

If the value is a primitive, it will be converted into a DicomTime as described in PrimitiveValue::to_time.

Source

pub fn to_multi_time(&self) -> Result<Vec<DicomTime>, ConvertValueError>

Retrieve and convert the primitive value into a sequence of DicomTimes.

If the value is a primitive, it will be converted into a vector of DicomTime as described in PrimitiveValue::to_multi_time.

Source

pub fn to_datetime(&self) -> Result<DicomDateTime, ConvertValueError>

Retrieve and convert the primitive value into a DicomDateTime.

If the value is a primitive, it will be converted into a DateTime as described in PrimitiveValue::to_datetime.

Source

pub fn to_multi_datetime(&self) -> Result<Vec<DicomDateTime>, ConvertValueError>

Retrieve and convert the primitive value into a sequence of DicomDateTimes.

If the value is a primitive, it will be converted into a vector of DicomDateTime as described in PrimitiveValue::to_multi_datetime.

Source

pub fn to_date_range(&self) -> Result<DateRange, ConvertValueError>

Retrieve and convert the primitive value into a DateRange.

If the value is a primitive, it will be converted into a DateRange as described in PrimitiveValue::to_date_range.

Source

pub fn to_time_range(&self) -> Result<TimeRange, ConvertValueError>

Retrieve and convert the primitive value into a TimeRange.

If the value is a primitive, it will be converted into a TimeRange as described in PrimitiveValue::to_time_range.

Source

pub fn to_datetime_range(&self) -> Result<DateTimeRange, ConvertValueError>

Retrieve and convert the primitive value into a DateTimeRange.

If the value is a primitive, it will be converted into a DateTimeRange as described in PrimitiveValue::to_datetime_range.

Source

pub fn to_tag(&self) -> Result<Tag, CastValueError>

Retrieves the primitive value as a DICOM tag.

Source

pub fn to_person_name(&self) -> Result<PersonName<'_>, ConvertValueError>

Retrieves the primitive value as a PersonName.

Source§

impl<I, P> Value<I, P>

Source

pub fn string(&self) -> Result<&str, CastValueError>

Get a single string value.

If it contains multiple strings, only the first one is returned.

An error is returned if the variant is not compatible.

To enable conversions of other variants to a textual representation, see to_str() instead.

Source

pub fn strings(&self) -> Result<&[String], CastValueError>

Get the inner sequence of string values if the variant is either Str or Strs.

An error is returned if the variant is not compatible.

To enable conversions of other variants to a textual representation, see to_str() instead.

Source

pub fn tag(&self) -> Result<Tag, CastValueError>

Get a single value of the requested type.

If it contains multiple values, only the first one is returned. An error is returned if the variant is not compatible.

Source

pub fn tags(&self) -> Result<&[Tag], CastValueError>

Get a sequence of values of the requested type without copying.

An error is returned if the variant is not compatible.

Source

pub fn date(&self) -> Result<DicomDate, CastValueError>

Get a single value of the requested type.

If it contains multiple values, only the first one is returned. An error is returned if the variant is not compatible.

Source

pub fn dates(&self) -> Result<&[DicomDate], CastValueError>

Get a sequence of values of the requested type without copying.

An error is returned if the variant is not compatible.

Source

pub fn time(&self) -> Result<DicomTime, CastValueError>

Get a single value of the requested type.

If it contains multiple values, only the first one is returned. An error is returned if the variant is not compatible.

Source

pub fn times(&self) -> Result<&[DicomTime], CastValueError>

Get a sequence of values of the requested type without copying.

An error is returned if the variant is not compatible.

Source

pub fn datetime(&self) -> Result<DicomDateTime, CastValueError>

Get a single value of the requested type.

If it contains multiple values, only the first one is returned. An error is returned if the variant is not compatible.

Source

pub fn datetimes(&self) -> Result<&[DicomDateTime], CastValueError>

Get a sequence of values of the requested type without copying.

An error is returned if the variant is not compatible.

Source

pub fn uint8(&self) -> Result<u8, CastValueError>

Get a single value of the requested type.

If it contains multiple values, only the first one is returned. An error is returned if the variant is not compatible.

Source

pub fn uint8_slice(&self) -> Result<&[u8], CastValueError>

Get a sequence of values of the requested type without copying.

An error is returned if the variant is not compatible.

Source

pub fn uint16(&self) -> Result<u16, CastValueError>

Get a single value of the requested type.

If it contains multiple values, only the first one is returned. An error is returned if the variant is not compatible.

Source

pub fn uint16_slice(&self) -> Result<&[u16], CastValueError>

Get a sequence of values of the requested type without copying.

An error is returned if the variant is not compatible.

Source

pub fn int16(&self) -> Result<i16, CastValueError>

Get a single value of the requested type.

If it contains multiple values, only the first one is returned. An error is returned if the variant is not compatible.

Source

pub fn int16_slice(&self) -> Result<&[i16], CastValueError>

Get a sequence of values of the requested type without copying.

An error is returned if the variant is not compatible.

Source

pub fn uint32(&self) -> Result<u32, CastValueError>

Get a single value of the requested type.

If it contains multiple values, only the first one is returned. An error is returned if the variant is not compatible.

Source

pub fn uint32_slice(&self) -> Result<&[u32], CastValueError>

Get a sequence of values of the requested type without copying.

An error is returned if the variant is not compatible.

Source

pub fn int32(&self) -> Result<i32, CastValueError>

Get a single value of the requested type.

If it contains multiple values, only the first one is returned. An error is returned if the variant is not compatible.

Source

pub fn int32_slice(&self) -> Result<&[i32], CastValueError>

Get a sequence of values of the requested type without copying.

An error is returned if the variant is not compatible.

Source

pub fn int64(&self) -> Result<i64, CastValueError>

Get a single value of the requested type.

If it contains multiple values, only the first one is returned. An error is returned if the variant is not compatible.

Source

pub fn int64_slice(&self) -> Result<&[i64], CastValueError>

Get a sequence of values of the requested type without copying.

An error is returned if the variant is not compatible.

Source

pub fn uint64(&self) -> Result<u64, CastValueError>

Get a single value of the requested type.

If it contains multiple values, only the first one is returned. An error is returned if the variant is not compatible.

Source

pub fn uint64_slice(&self) -> Result<&[u64], CastValueError>

Get a sequence of values of the requested type without copying.

An error is returned if the variant is not compatible.

Source

pub fn float32(&self) -> Result<f32, CastValueError>

Get a single value of the requested type.

If it contains multiple values, only the first one is returned. An error is returned if the variant is not compatible.

Source

pub fn float32_slice(&self) -> Result<&[f32], CastValueError>

Get a sequence of values of the requested type without copying.

An error is returned if the variant is not compatible.

Source

pub fn float64(&self) -> Result<f64, CastValueError>

Get a single value of the requested type.

If it contains multiple values, only the first one is returned. An error is returned if the variant is not compatible.

Source

pub fn float64_slice(&self) -> Result<&[f64], CastValueError>

Get a sequence of values of the requested type without copying.

An error is returned if the variant is not compatible.

Trait Implementations§

Source§

impl<I: Clone, P: Clone> Clone for Value<I, P>

Source§

fn clone(&self) -> Value<I, P>

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<I: Debug, P: Debug> Debug for Value<I, P>

Source§

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

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

impl<I, P> DicomValueType for Value<I, P>

Source§

fn value_type(&self) -> ValueType

Retrieve the specific type of this value.
Source§

fn cardinality(&self) -> usize

Retrieve the number of elements contained in the DICOM value. Read more
Source§

impl<I, P> From<&str> for Value<I, P>

Source§

fn from(value: &str) -> Self

Converts a string into a primitive textual value.

Source§

impl<I, P> From<DataSetSequence<I>> for Value<I, P>

Source§

fn from(value: DataSetSequence<I>) -> Self

Converts to this type from the input type.
Source§

impl<I, P> From<DicomDate> for Value<I, P>

Source§

fn from(value: DicomDate) -> Self

Converts the DICOM date into a primitive value.

Source§

impl<I, P> From<DicomDateTime> for Value<I, P>

Source§

fn from(value: DicomDateTime) -> Self

Converts the DICOM date-time into a primitive value.

Source§

impl<I, P> From<DicomTime> for Value<I, P>

Source§

fn from(value: DicomTime) -> Self

Converts the DICOM time into a primitive value.

Source§

impl<I, P> From<PixelFragmentSequence<P>> for Value<I, P>

Source§

fn from(value: PixelFragmentSequence<P>) -> Self

Converts to this type from the input type.
Source§

impl<I, P> From<PrimitiveValue> for Value<I, P>

Source§

fn from(v: PrimitiveValue) -> Self

Converts to this type from the input type.
Source§

impl<I, P> From<String> for Value<I, P>

Source§

fn from(value: String) -> Self

Converts a string into a primitive textual value.

Source§

impl<I, P> HasLength for Value<I, P>

Source§

fn length(&self) -> Length

Retrieve the value data’s length as specified by the data element or item, in bytes. Read more
Source§

fn is_empty(&self) -> bool

Check whether the value is empty (0 length).
Source§

impl<I: PartialEq, P: PartialEq> PartialEq for Value<I, P>

Source§

fn eq(&self, other: &Value<I, P>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<I, P> StructuralPartialEq for Value<I, P>

Auto Trait Implementations§

§

impl<I, P> Freeze for Value<I, P>
where I: Freeze, P: Freeze,

§

impl<I, P> RefUnwindSafe for Value<I, P>

§

impl<I, P> Send for Value<I, P>
where I: Send, P: Send,

§

impl<I, P> Sync for Value<I, P>
where I: Sync, P: Sync,

§

impl<I, P> Unpin for Value<I, P>
where I: Unpin, P: Unpin,

§

impl<I, P> UnwindSafe for Value<I, P>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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,

Source§

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

Source§

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

Source§

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.