Struct dicom_core::value::partial::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

source

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

source

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

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

§

type PreciseValue = NaiveDate

§

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

source§

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

§

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

§

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

§

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.