Trait dicom_core::value::range::AsRange
source · pub trait AsRange: Precision {
type Item: PartialEq + PartialOrd;
type Range;
// Required methods
fn earliest(&self) -> Result<Self::Item, Error>;
fn latest(&self) -> Result<Self::Item, Error>;
fn range(&self) -> Result<Self::Range, Error>;
// Provided methods
fn exact(&self) -> Result<Self::Item, Error> { ... }
fn is_precise(&self) -> bool { ... }
}Expand description
The DICOM protocol accepts date / time values with null components.
Imprecise values are to be handled as date / time ranges.
This trait is implemented by date / time structures with partial precision.
If the date / time structure is not precise, it is up to the user to call one of these
methods to retrieve a suitable chrono value.
Examples
use chrono::{NaiveDate, NaiveTime};
use dicom_core::value::{AsRange, DicomDate, DicomTime, TimeRange};
let dicom_date = DicomDate::from_ym(2010,1)?;
assert_eq!(dicom_date.is_precise(), false);
assert_eq!(
Some(dicom_date.earliest()?),
NaiveDate::from_ymd_opt(2010,1,1)
);
assert_eq!(
Some(dicom_date.latest()?),
NaiveDate::from_ymd_opt(2010,1,31)
);
let dicom_time = DicomTime::from_hm(10,0)?;
assert_eq!(
dicom_time.range()?,
TimeRange::from_start_to_end(NaiveTime::from_hms(10, 0, 0),
NaiveTime::from_hms_micro_opt(10, 0, 59, 999_999).unwrap())?
);
// only a time with 6 digits second fraction is considered precise
assert!(dicom_time.exact().is_err());
Required Associated Types§
Required Methods§
sourcefn earliest(&self) -> Result<Self::Item, Error>
fn earliest(&self) -> Result<Self::Item, Error>
Returns the earliest possible chrono 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.
Provided Methods§
sourcefn exact(&self) -> Result<Self::Item, Error>
fn exact(&self) -> Result<Self::Item, Error>
Returns a corresponding chrono value, if the partial precision structure has full accuracy.
sourcefn is_precise(&self) -> bool
fn is_precise(&self) -> bool
Returns true if partial precision structure has the maximum possible accuracy.
For fraction of a second, the full 6 digits are required for the value to be precise.