dicom_core::value::partial

Struct DicomDate

Source
pub struct DicomDate(/* private fields */);
Expand description

Represents a Dicom date (DA) value with a partial precision, where some date components may be missing.

Unlike chrono::NaiveDate, it does not allow for negative years.

DicomDate implements AsRange trait, enabling to retrieve specific date values.

§Example

use chrono::NaiveDate;
use dicom_core::value::{DicomDate, AsRange};

let date = DicomDate::from_y(1492)?;

assert_eq!(
    Some(date.latest()?),
    NaiveDate::from_ymd_opt(1492,12,31)
);

let date = DicomDate::try_from(&NaiveDate::from_ymd_opt(1900, 5, 3).unwrap())?;
// conversion from chrono value leads to a precise value
assert_eq!(date.is_precise(), true);

assert_eq!(date.to_string(), "1900-05-03");

Implementations§

Source§

impl DicomDate

Source

pub fn from_y(year: u16) -> Result<DicomDate, Error>

Constructs a new DicomDate with year precision (YYYY)

Source

pub fn from_ym(year: u16, month: u8) -> Result<DicomDate, Error>

Constructs a new DicomDate with year and month precision (YYYYMM)

Source

pub fn from_ymd(year: u16, month: u8, day: u8) -> Result<DicomDate, Error>

Constructs a new DicomDate with a year, month and day precision (YYYYMMDD)

Source

pub fn year(&self) -> &u16

Retrieves the year from a date as a reference

Source

pub fn month(&self) -> Option<&u8>

Retrieves the month from a date as a reference

Source

pub fn day(&self) -> Option<&u8>

Retrieves the day from a date as a reference

Source§

impl DicomDate

Source

pub fn to_encoded(&self) -> String

Retrieves a dicom encoded string representation of the value.

Source§

impl DicomDate

Source

pub fn to_naive_date(self) -> Result<NaiveDate, Error>

Retrieves a chrono::NaiveDate if the value is precise up to the day of the month.

Trait Implementations§

Source§

impl AsRange for DicomDate

Source§

type PreciseValue = NaiveDate

Source§

type Range = DateRange

Source§

fn is_precise(&self) -> bool

returns true if value has all possible date / time components
Source§

fn earliest(&self) -> Result<Self::PreciseValue, Error>

Returns the earliest possible value from a partial precision structure. Missing components default to 1 (days, months) or 0 (hours, minutes, …) If structure contains invalid combination of DateComponents, it fails.
Source§

fn latest(&self) -> Result<Self::PreciseValue, Error>

Returns the latest possible value from a partial precision structure. If structure contains invalid combination of DateComponents, it fails.
Source§

fn range(&self) -> Result<Self::Range, Error>

Returns a tuple of the earliest and latest possible value from a partial precision structure.
Source§

fn exact(&self) -> Result<Self::PreciseValue, Error>

Returns a corresponding precise value, if the partial precision structure has full accuracy.
Source§

impl Clone for DicomDate

Source§

fn clone(&self) -> DicomDate

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 Debug for DicomDate

Source§

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

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

impl Display for DicomDate

Source§

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

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

impl From<DicomDate> for PrimitiveValue

Source§

fn from(value: DicomDate) -> 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 PartialEq for DicomDate

Source§

fn eq(&self, other: &DicomDate) -> 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 TryFrom<&NaiveDate> for DicomDate

Source§

type Error = Error

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

fn try_from(date: &NaiveDate) -> Result<Self, Error>

Performs the conversion.
Source§

impl Copy for DicomDate

Source§

impl StructuralPartialEq for DicomDate

Auto Trait Implementations§

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> ToString for T
where T: Display + ?Sized,

Source§

default fn to_string(&self) -> String

Converts the given value to a String. 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.