pub enum PrimitiveValue {
Show 16 variants
Empty,
Strs(SmallVec<[String; 2]>),
Str(String),
Tags(SmallVec<[Tag; 2]>),
U8(SmallVec<[u8; 2]>),
I16(SmallVec<[i16; 2]>),
U16(SmallVec<[u16; 2]>),
I32(SmallVec<[i32; 2]>),
U32(SmallVec<[u32; 2]>),
I64(SmallVec<[i64; 2]>),
U64(SmallVec<[u64; 2]>),
F32(SmallVec<[f32; 2]>),
F64(SmallVec<[f64; 2]>),
Date(SmallVec<[DicomDate; 2]>),
DateTime(SmallVec<[DicomDateTime; 2]>),
Time(SmallVec<[DicomTime; 2]>),
}
Expand description
An enum representing a primitive value from a DICOM element. The result of decoding an element’s data value may be one of the enumerated types depending on its content and value representation.
Multiple elements are contained in a smallvec
vector,
conveniently aliased to the type C
.
See the macro dicom_value!
for a more intuitive means
of constructing these values.
Alternatively, From
conversions into PrimitiveValue
exist
for single element types,
including numeric types, String
, and &str
.
§Example
let value = PrimitiveValue::from("Smith^John");
assert_eq!(value, PrimitiveValue::Str("Smith^John".to_string()));
assert_eq!(value.multiplicity(), 1);
let value = PrimitiveValue::from(512_u16);
assert_eq!(value, PrimitiveValue::U16(smallvec![512]));
Variants§
Empty
No data. Usually employed for zero-length values.
Strs(SmallVec<[String; 2]>)
A sequence of strings. Used for AE, AS, PN, SH, CS, LO, UI and UC. Can also be used for IS, SS, DS, DA, DT and TM when decoding with format preservation.
Str(String)
A single string. Used for ST, LT, UT and UR, which are never multi-valued.
Tags(SmallVec<[Tag; 2]>)
A sequence of attribute tags. Used specifically for AT.
U8(SmallVec<[u8; 2]>)
The value is a sequence of unsigned 8-bit integers. Used for OB and UN.
I16(SmallVec<[i16; 2]>)
The value is a sequence of signed 16-bit integers. Used for SS.
U16(SmallVec<[u16; 2]>)
A sequence of unsigned 16-bit integers. Used for US and OW.
I32(SmallVec<[i32; 2]>)
A sequence of signed 32-bit integers. Used for SL and IS.
U32(SmallVec<[u32; 2]>)
A sequence of unsigned 32-bit integers. Used for UL and OL.
I64(SmallVec<[i64; 2]>)
A sequence of signed 64-bit integers. Used for SV.
U64(SmallVec<[u64; 2]>)
A sequence of unsigned 64-bit integers. Used for UV and OV.
F32(SmallVec<[f32; 2]>)
The value is a sequence of 32-bit floating point numbers. Used for OF and FL.
F64(SmallVec<[f64; 2]>)
The value is a sequence of 64-bit floating point numbers. Used for OD and FD, DS.
Date(SmallVec<[DicomDate; 2]>)
A sequence of dates with arbitrary precision. Used for the DA representation.
DateTime(SmallVec<[DicomDateTime; 2]>)
A sequence of date-time values with arbitrary precision. Used for the DT representation.
Time(SmallVec<[DicomTime; 2]>)
A sequence of time values with arbitrary precision. Used for the TM representation.
Implementations§
Source§impl PrimitiveValue
impl PrimitiveValue
Sourcepub fn multiplicity(&self) -> u32
pub fn multiplicity(&self) -> u32
Obtain the number of individual elements. This number may not match the DICOM value multiplicity in some value representations.
Sourcepub fn calculate_byte_len(&self) -> usize
pub fn calculate_byte_len(&self) -> usize
Determine the length of the DICOM value in its encoded form.
In other words, this is the number of bytes that the value would need to occupy in a DICOM file, without compression and without the element header. The output is always an even number, so as to consider the mandatory trailing padding.
This method is particularly useful for presenting an estimated space occupation to the end user. However, consumers should not depend on this number for decoding or encoding values. The calculated number does not need to match the length of the original byte stream from where the value was originally decoded.
Sourcepub fn to_str(&self) -> Cow<'_, str>
pub fn to_str(&self) -> Cow<'_, str>
Convert the primitive value into a string representation.
String values already encoded with the Str
and Strs
variants
are provided as is.
In the case of Strs
, the strings are first joined together
with a backslash ('\\'
).
All other type variants are first converted to a string,
then joined together with a backslash.
Trailing whitespace is stripped from each string.
Note:
As the process of reading a DICOM value
may not always preserve its original nature,
it is not guaranteed that to_str()
returns a string with
the exact same byte sequence as the one originally found
at the source of the value,
even for the string variants.
Therefore, this method is not reliable
for compliant DICOM serialization.
§Examples
assert_eq!(
dicom_value!(Str, "Smith^John").to_str(),
"Smith^John",
);
assert_eq!(
dicom_value!(Date, DicomDate::from_y(2014)?).to_str(),
"2014",
);
assert_eq!(
dicom_value!(Str, "Smith^John\0").to_str(),
"Smith^John",
);
assert_eq!(
dicom_value!(Strs, [
"DERIVED",
"PRIMARY",
"WHOLE BODY",
"EMISSION",
])
.to_str(),
"DERIVED\\PRIMARY\\WHOLE BODY\\EMISSION",
);
Ok(())
}
Sourcepub fn to_raw_str(&self) -> Cow<'_, str>
pub fn to_raw_str(&self) -> Cow<'_, str>
Convert the primitive value into a raw string representation.
String values already encoded with the Str
and Strs
variants
are provided as is.
In the case of Strs
, the strings are first joined together
with a backslash ('\\'
).
All other type variants are first converted to a string,
then joined together with a backslash.
This method keeps all trailing whitespace,
unlike to_str()
.
Note:
As the process of reading a DICOM value
may not always preserve its original nature,
it is not guaranteed that to_raw_str()
returns a string with
the exact same byte sequence as the one originally found
at the source of the value,
even for the string variants.
Therefore, this method is not reliable
for compliant DICOM serialization.
§Examples
assert_eq!(
dicom_value!(Str, "Smith^John\0").to_raw_str(),
"Smith^John\0",
);
assert_eq!(
dicom_value!(Date, DicomDate::from_ymd(2014, 10, 12).unwrap()).to_raw_str(),
"2014-10-12",
);
assert_eq!(
dicom_value!(Strs, [
"DERIVED",
" PRIMARY ",
"WHOLE BODY",
"EMISSION ",
])
.to_raw_str(),
"DERIVED\\ PRIMARY \\WHOLE BODY\\EMISSION ",
);
Sourcepub fn to_multi_str(&self) -> Cow<'_, [String]>
pub fn to_multi_str(&self) -> Cow<'_, [String]>
Convert the primitive value into a multi-string representation.
String values already encoded with the Str
and Strs
variants
are provided as is.
All other type variants are first converted to a string,
then collected into a vector.
Trailing whitespace is stripped from each string.
If keeping it is desired,
use to_raw_str()
.
Note:
As the process of reading a DICOM value
may not always preserve its original nature,
it is not guaranteed that to_multi_str()
returns strings with
the exact same byte sequence as the one originally found
at the source of the value,
even for the string variants.
Therefore, this method is not reliable
for compliant DICOM serialization.
§Examples
assert_eq!(
dicom_value!(Strs, [
"DERIVED",
"PRIMARY",
"WHOLE BODY ",
" EMISSION ",
])
.to_multi_str(),
&["DERIVED", "PRIMARY", "WHOLE BODY", " EMISSION"][..],
);
assert_eq!(
dicom_value!(Str, "Smith^John").to_multi_str(),
&["Smith^John"][..],
);
assert_eq!(
dicom_value!(Str, "Smith^John\0").to_multi_str(),
&["Smith^John"][..],
);
assert_eq!(
dicom_value!(Date, DicomDate::from_ym(2014, 10)?).to_multi_str(),
&["201410"][..],
);
assert_eq!(
dicom_value!(I64, [128, 256, 512]).to_multi_str(),
&["128", "256", "512"][..],
);
Ok(())
}
Sourcepub fn to_bytes(&self) -> Cow<'_, [u8]>
pub fn to_bytes(&self) -> Cow<'_, [u8]>
Retrieve this DICOM value as raw bytes.
Binary numeric values are returned with a reinterpretation of the holding vector’s occupied data block as bytes, without copying, under the platform’s native byte order.
String values already encoded with the Str
and Strs
variants
are provided as their respective bytes in UTF-8.
In the case of Strs
, the strings are first joined together
with a backslash ('\\'
).
Other type variants are first converted to a string,
joined together with a backslash,
then turned into a byte vector.
For values which are inherently textual according the standard,
this is equivalent to calling as_bytes()
after to_str()
.
Note:
As the process of reading a DICOM value
may not always preserve its original nature,
it is not guaranteed that to_bytes()
returns the same byte sequence
as the one originally found at the source of the value.
Therefore, this method is not reliable
for compliant DICOM serialization.
§Examples
U8
provides a straight, zero-copy slice of bytes.
assert_eq!(
PrimitiveValue::U8(smallvec![
1, 2, 5,
]).to_bytes(),
&[1, 2, 5][..],
);
Other values are converted to text first.
assert_eq!(
PrimitiveValue::from("Smith^John").to_bytes(),
&b"Smith^John"[..],
);
assert_eq!(
PrimitiveValue::from(DicomDate::from_ymd(2014, 10, 12)?)
.to_bytes(),
&b"2014-10-12"[..],
);
assert_eq!(
dicom_value!(Strs, [
"DERIVED",
"PRIMARY",
"WHOLE BODY",
"EMISSION",
])
.to_bytes(),
&b"DERIVED\\PRIMARY\\WHOLE BODY\\EMISSION"[..],
);
Ok(())
}
Sourcepub fn to_int<T>(&self) -> Result<T, ConvertValueError>
pub fn to_int<T>(&self) -> Result<T, ConvertValueError>
Retrieve a single integer of type T
from this value.
If the value is already represented as an integer, it is returned after a conversion to the target type. An error is returned if the integer cannot be represented by the given integer type. If the value is a string or sequence of strings, the first string is parsed to obtain an integer, potentially failing if the string does not represent a valid integer. The string is stripped of leading/trailing whitespace before parsing. If the value is a sequence of U8 bytes, the bytes are individually interpreted as independent numbers. Otherwise, the operation fails.
Note that this method does not enable
the conversion of floating point numbers to integers via truncation.
If this is intentional,
retrieve a float via to_float32
or to_float64
instead,
then cast it to an integer.
§Example
assert_eq!(
PrimitiveValue::I32(smallvec![
1, 2, 5,
])
.to_int::<u32>().ok(),
Some(1_u32),
);
assert_eq!(
PrimitiveValue::from("505 ").to_int::<i32>().ok(),
Some(505),
);
Sourcepub fn to_multi_int<T>(&self) -> Result<Vec<T>, ConvertValueError>
pub fn to_multi_int<T>(&self) -> Result<Vec<T>, ConvertValueError>
Retrieve a sequence of integers of type T
from this value.
If the values is already represented as an integer,
it is returned after a NumCast
conversion to the target type.
An error is returned if any of the integers cannot be represented
by the given integer type.
If the value is a string or sequence of strings,
each string is parsed to obtain an integer,
potentially failing if the string does not represent a valid integer.
The string is stripped of leading/trailing whitespace before parsing.
If the value is a sequence of U8 bytes,
the bytes are individually interpreted as independent numbers.
Otherwise, the operation fails.
Note that this method does not enable
the conversion of floating point numbers to integers via truncation.
If this is intentional,
retrieve a float via to_float32
or to_float64
instead,
then cast it to an integer.
§Example
assert_eq!(
PrimitiveValue::I32(smallvec![
1, 2, 5,
])
.to_multi_int::<u32>().ok(),
Some(vec![1_u32, 2, 5]),
);
assert_eq!(
dicom_value!(Strs, ["5050", "23 "]).to_multi_int::<i32>().ok(),
Some(vec![5050, 23]),
);
Sourcepub fn to_float32(&self) -> Result<f32, ConvertValueError>
pub fn to_float32(&self) -> Result<f32, ConvertValueError>
Retrieve one single-precision floating point from this value.
If the value is already represented as a number,
it is returned after a conversion to f32
.
An error is returned if the number cannot be represented
by the given number type.
If the value is a string or sequence of strings,
the first string is parsed to obtain a number,
potentially failing if the string does not represent a valid number.
The string is stripped of leading/trailing whitespace before parsing.
If the value is a sequence of U8 bytes,
the bytes are individually interpreted as independent numbers.
Otherwise, the operation fails.
§Example
assert_eq!(
PrimitiveValue::F32(smallvec![
1.5, 2., 5.,
])
.to_float32().ok(),
Some(1.5_f32),
);
assert_eq!(
PrimitiveValue::from("-6.75 ").to_float32().ok(),
Some(-6.75),
);
Sourcepub fn to_multi_float32(&self) -> Result<Vec<f32>, ConvertValueError>
pub fn to_multi_float32(&self) -> Result<Vec<f32>, ConvertValueError>
Retrieve a sequence of single-precision floating point numbers from this value.
If the value is already represented as numbers,
they are returned after a conversion to f32
.
An error is returned if any of the numbers cannot be represented
by an f32
.
If the value is a string or sequence of strings,
the strings are parsed to obtain a number,
potentially failing if the string does not represent a valid number.
The string is stripped of leading/trailing whitespace before parsing.
If the value is a sequence of U8 bytes,
the bytes are individually interpreted as independent numbers.
Otherwise, the operation fails.
§Example
assert_eq!(
PrimitiveValue::F32(smallvec![
1.5, 2., 5.,
])
.to_multi_float32().ok(),
Some(vec![1.5_f32, 2., 5.]),
);
assert_eq!(
PrimitiveValue::from("-6.75 ").to_multi_float32().ok(),
Some(vec![-6.75]),
);
Sourcepub fn to_float64(&self) -> Result<f64, ConvertValueError>
pub fn to_float64(&self) -> Result<f64, ConvertValueError>
Retrieve one double-precision floating point from this value.
If the value is already represented as a number,
it is returned after a conversion to f64
.
An error is returned if the number cannot be represented
by the given number type.
If the value is a string or sequence of strings,
the first string is parsed to obtain a number,
potentially failing if the string does not represent a valid number.
The string is stripped of leading/trailing whitespace before parsing.
If the value is a sequence of U8 bytes,
the bytes are individually interpreted as independent numbers.
Otherwise, the operation fails.
§Example
assert_eq!(
PrimitiveValue::F64(smallvec![
1.5, 2., 5.,
])
.to_float64().ok(),
Some(1.5_f64),
);
assert_eq!(
PrimitiveValue::from("-6.75 ").to_float64().ok(),
Some(-6.75),
);
Sourcepub fn to_multi_float64(&self) -> Result<Vec<f64>, ConvertValueError>
pub fn to_multi_float64(&self) -> Result<Vec<f64>, ConvertValueError>
Retrieve a sequence of double-precision floating point numbers from this value.
If the value is already represented as numbers,
they are returned after a conversion to f64
.
An error is returned if any of the numbers cannot be represented
by an f64
.
If the value is a string or sequence of strings,
the strings are parsed to obtain a number,
potentially failing if the string does not represent a valid number.
The string is stripped of leading/trailing whitespace before parsing.
If the value is a sequence of U8 bytes,
the bytes are individually interpreted as independent numbers.
Otherwise, the operation fails.
§Example
assert_eq!(
PrimitiveValue::F64(smallvec![
1.5, 2., 5.,
])
.to_multi_float64().ok(),
Some(vec![1.5_f64, 2., 5.]),
);
assert_eq!(
PrimitiveValue::from("-6.75 ").to_multi_float64().ok(),
Some(vec![-6.75]),
);
Sourcepub fn to_naive_date(&self) -> Result<NaiveDate, ConvertValueError>
pub fn to_naive_date(&self) -> Result<NaiveDate, ConvertValueError>
Retrieve a single chrono::NaiveDate
from this value.
Please note, that this is a shortcut to obtain a usable date from a primitive value.
As per standard, the stored value might not be precise. It is highly recommended to
use .to_date()
as the only way to obtain dates.
If the value is already represented as a precise DicomDate
, it is converted
to a NaiveDate
value. It fails for imprecise values.
If the value is a string or sequence of strings,
the first string is decoded to obtain a date, potentially failing if the
string does not represent a valid date.
If the value is a sequence of U8 bytes, the bytes are
first interpreted as an ASCII character string.
Users are advised that this method is DICOM compliant and a full date representation of YYYYMMDD is required. Otherwise, the operation fails.
Partial precision dates are handled by DicomDate
, which can be retrieved
by .to_date()
.
§Example
assert_eq!(
PrimitiveValue::Date(smallvec![
DicomDate::from_ymd(2014, 10, 12)?,
])
.to_naive_date().ok(),
Some(NaiveDate::from_ymd(2014, 10, 12)),
);
assert_eq!(
PrimitiveValue::Strs(smallvec![
"20141012".to_string(),
])
.to_naive_date().ok(),
Some(NaiveDate::from_ymd(2014, 10, 12)),
);
assert!(
PrimitiveValue::Str("201410".to_string())
.to_naive_date().is_err()
);
Sourcepub fn to_multi_naive_date(&self) -> Result<Vec<NaiveDate>, ConvertValueError>
pub fn to_multi_naive_date(&self) -> Result<Vec<NaiveDate>, ConvertValueError>
Retrieve the full sequence of chrono::NaiveDate
s from this value.
Please note, that this is a shortcut to obtain usable dates from a primitive value.
As per standard, the stored values might not be precise. It is highly recommended to
use .to_multi_date()
as the only way to obtain dates.
If the value is already represented as a sequence of precise DicomDate
values,
it is converted. It fails for imprecise values.
If the value is a string or sequence of strings,
the strings are decoded to obtain a date, potentially failing if
any of the strings does not represent a valid date.
If the value is a sequence of U8 bytes, the bytes are
first interpreted as an ASCII character string,
then as a backslash-separated list of dates.
Users are advised that this method is DICOM compliant and a full date representation of YYYYMMDD is required. Otherwise, the operation fails.
Partial precision dates are handled by DicomDate
, which can be retrieved
by .to_multi_date()
.
§Example
assert_eq!(
PrimitiveValue::Date(smallvec![
DicomDate::from_ymd(2014, 10, 12)?,
]).to_multi_naive_date().ok(),
Some(vec![NaiveDate::from_ymd(2014, 10, 12)]),
);
assert_eq!(
PrimitiveValue::Strs(smallvec![
"20141012".to_string(),
"20200828".to_string(),
]).to_multi_naive_date().ok(),
Some(vec![
NaiveDate::from_ymd(2014, 10, 12),
NaiveDate::from_ymd(2020, 8, 28),
]),
);
Sourcepub fn to_date(&self) -> Result<DicomDate, ConvertValueError>
pub fn to_date(&self) -> Result<DicomDate, ConvertValueError>
Retrieve a single DicomDate
from this value.
If the value is already represented as a DicomDate
, it is returned.
If the value is a string or sequence of strings,
the first string is decoded to obtain a DicomDate, potentially failing if the
string does not represent a valid DicomDate.
If the value is a sequence of U8 bytes, the bytes are
first interpreted as an ASCII character string.
Unlike Rust’s chrono::NaiveDate
, DicomDate
allows for missing date components.
DicomDate implements AsRange
trait, so specific chrono::NaiveDate
values can be retrieved.
§Example
use dicom_core::value::{AsRange, DicomDate};
let value = PrimitiveValue::Str("200002".into());
let date = value.to_date()?;
// it is not precise, day of month is unspecified
assert_eq!(
date.is_precise(),
false
);
assert_eq!(
date.earliest()?,
NaiveDate::from_ymd(2000,2,1)
);
assert_eq!(
date.latest()?,
NaiveDate::from_ymd(2000,2,29)
);
assert!(date.exact().is_err());
let date = PrimitiveValue::Str("20000201".into()).to_date()?;
assert_eq!(
date.is_precise(),
true
);
// .to_naive_date() works only for precise values
assert_eq!(
date.exact()?,
date.to_naive_date()?
);
Sourcepub fn to_multi_date(&self) -> Result<Vec<DicomDate>, ConvertValueError>
pub fn to_multi_date(&self) -> Result<Vec<DicomDate>, ConvertValueError>
Retrieve the full sequence of DicomDate
s from this value.
§Example
use dicom_core::value::DicomDate;
assert_eq!(
dicom_value!(Strs, ["201410", "2020", "20200101"])
.to_multi_date()?,
vec![
DicomDate::from_ym(2014, 10)?,
DicomDate::from_y(2020)?,
DicomDate::from_ymd(2020, 1, 1)?
]);
Sourcepub fn to_naive_time(&self) -> Result<NaiveTime, ConvertValueError>
pub fn to_naive_time(&self) -> Result<NaiveTime, ConvertValueError>
Retrieve a single chrono::NaiveTime
from this value.
Please note, that this is a shortcut to obtain a usable time from a primitive value.
As per standard, the stored value might not be precise. It is highly recommended to
use .to_time()
as the only way to obtain times.
If the value is represented as a precise DicomTime
,
it is converted to a NaiveTime
.
It fails for imprecise values,
as in, those which do not specify up to at least the seconds.
If the value is a string or sequence of strings,
the first string is decoded to obtain a time, potentially failing if the
string does not represent a valid time.
If the value is a sequence of U8 bytes, the bytes are
first interpreted as an ASCII character string.
Otherwise, the operation fails.
Partial precision times are handled by DicomTime
,
which can be retrieved by .to_time()
.
§Example
assert_eq!(
PrimitiveValue::from(DicomTime::from_hms(11, 2, 45)?).to_naive_time().ok(),
Some(NaiveTime::from_hms(11, 2, 45)),
);
assert_eq!(
PrimitiveValue::from("110245.78").to_naive_time().ok(),
Some(NaiveTime::from_hms_milli(11, 2, 45, 780)),
);
Sourcepub fn to_multi_naive_time(&self) -> Result<Vec<NaiveTime>, ConvertValueError>
pub fn to_multi_naive_time(&self) -> Result<Vec<NaiveTime>, ConvertValueError>
Retrieve the full sequence of chrono::NaiveTime
s from this value.
Please note, that this is a shortcut to obtain a usable time from a primitive value.
As per standard, the stored values might not be precise. It is highly recommended to
use .to_multi_time()
as the only way to obtain times.
If the value is already represented as a sequence of precise DicomTime
values,
it is converted to a sequence of NaiveTime
values. It fails for imprecise values.
If the value is a string or sequence of strings,
the strings are decoded to obtain a date, potentially failing if
any of the strings does not represent a valid date.
If the value is a sequence of U8 bytes, the bytes are
first interpreted as an ASCII character string,
then as a backslash-separated list of times.
Otherwise, the operation fails.
Users are advised that this method requires at least 1 out of 6 digits of the second fraction .F to be present. Otherwise, the operation fails.
Partial precision times are handled by DicomTime
,
which can be retrieved by .to_multi_time()
.
§Example
assert_eq!(
PrimitiveValue::from(DicomTime::from_hms(22, 58, 2)?).to_multi_naive_time().ok(),
Some(vec![NaiveTime::from_hms(22, 58, 2)]),
);
assert_eq!(
PrimitiveValue::Strs(smallvec![
"225802.1".to_string(),
"225916.742388".to_string(),
]).to_multi_naive_time().ok(),
Some(vec![
NaiveTime::from_hms_micro(22, 58, 2, 100_000),
NaiveTime::from_hms_micro(22, 59, 16, 742_388),
]),
);
Sourcepub fn to_time(&self) -> Result<DicomTime, ConvertValueError>
pub fn to_time(&self) -> Result<DicomTime, ConvertValueError>
Retrieve a single DicomTime
from this value.
If the value is already represented as a time, it is converted into DicomTime. If the value is a string or sequence of strings, the first string is decoded to obtain a DicomTime, potentially failing if the string does not represent a valid DicomTime. If the value is a sequence of U8 bytes, the bytes are first interpreted as an ASCII character string.
Unlike Rust’s chrono::NaiveTime
, DicomTime
allows for missing time components.
DicomTime implements AsRange
trait, so specific chrono::NaiveTime
values can be retrieved.
§Example
use dicom_core::value::{AsRange, DicomTime};
let value = PrimitiveValue::Str("10".into());
let time = value.to_time()?;
// is not precise, minute, second and second fraction are unspecified
assert_eq!(
time.is_precise(),
false
);
assert_eq!(
time.earliest()?,
NaiveTime::from_hms(10,0,0)
);
assert_eq!(
time.latest()?,
NaiveTime::from_hms_micro(10,59,59,999_999)
);
assert!(time.exact().is_err());
let second = PrimitiveValue::Str("101259".into());
// not a precise value, fraction of second is unspecified
assert!(second.to_time()?.exact().is_err());
// .to_naive_time() yields a result, for at least second precision values
// second fraction defaults to zeros
assert_eq!(
second.to_time()?.to_naive_time()?,
NaiveTime::from_hms(10,12,59)
);
let fraction6 = PrimitiveValue::Str("101259.123456".into());
let fraction5 = PrimitiveValue::Str("101259.12345".into());
// is not precise, last digit of second fraction is unspecified
assert!(
fraction5.to_time()?.exact().is_err()
);
assert!(
fraction6.to_time()?.exact().is_ok()
);
assert_eq!(
fraction6.to_time()?.exact()?,
fraction6.to_time()?.to_naive_time()?
);
Sourcepub fn to_multi_time(&self) -> Result<Vec<DicomTime>, ConvertValueError>
pub fn to_multi_time(&self) -> Result<Vec<DicomTime>, ConvertValueError>
Retrieve the full sequence of DicomTime
s from this value.
If the value is already represented as a time, it is converted into DicomTime. If the value is a string or sequence of strings, the first string is decoded to obtain a DicomTime, potentially failing if the string does not represent a valid DicomTime. If the value is a sequence of U8 bytes, the bytes are first interpreted as an ASCII character string.
Unlike Rust’s chrono::NaiveTime
, DicomTime
allows for missing time components.
DicomTime implements AsRange
trait, so specific chrono::NaiveTime
values can be retrieved.
§Example
use dicom_core::value::DicomTime;
assert_eq!(
PrimitiveValue::Strs(smallvec![
"2258".to_string(),
"225916.000742".to_string(),
]).to_multi_time()?,
vec![
DicomTime::from_hm(22, 58)?,
DicomTime::from_hms_micro(22, 59, 16, 742)?,
],
);
pub fn to_chrono_datetime(&self)
to_datetime
insteadpub fn to_multi_chrono_datetime(&self)
to_multi_datetime
insteadSourcepub fn to_datetime(&self) -> Result<DicomDateTime, ConvertValueError>
pub fn to_datetime(&self) -> Result<DicomDateTime, ConvertValueError>
Retrieve a single DicomDateTime
from this value.
If the value is already represented as a date-time, it is converted into DicomDateTime. If the value is a string or sequence of strings, the first string is decoded to obtain a DicomDateTime, potentially failing if the string does not represent a valid DicomDateTime. If the value is a sequence of U8 bytes, the bytes are first interpreted as an ASCII character string.
Unlike Rust’s chrono::DateTime
, DicomDateTime
allows for missing date or time components.
DicomDateTime implements AsRange
trait, so specific chrono::DateTime
values can be retrieved.
§Example
use dicom_core::value::{DicomDateTime, AsRange, DateTimeRange, PreciseDateTime};
// let's parse a date-time text value with 0.1 second precision without a time-zone.
let dt_value = PrimitiveValue::from("20121221093001.1").to_datetime()?;
assert_eq!(
dt_value.earliest()?,
PreciseDateTime::Naive(NaiveDateTime::new(
NaiveDate::from_ymd_opt(2012, 12, 21).unwrap(),
NaiveTime::from_hms_micro_opt(9, 30, 1, 100_000).unwrap()
))
);
assert_eq!(
dt_value.latest()?,
PreciseDateTime::Naive(NaiveDateTime::new(
NaiveDate::from_ymd_opt(2012, 12, 21).unwrap(),
NaiveTime::from_hms_micro_opt(9, 30, 1, 199_999).unwrap()
))
);
let default_offset = FixedOffset::east_opt(3600).unwrap();
// let's parse a date-time text value with full precision with a time-zone east +01:00.
let dt_value = PrimitiveValue::from("20121221093001.123456+0100").to_datetime()?;
// date-time has all components
assert_eq!(dt_value.is_precise(), true);
assert_eq!(
dt_value.exact()?,
PreciseDateTime::TimeZone(
default_offset
.ymd_opt(2012, 12, 21).unwrap()
.and_hms_micro_opt(9, 30, 1, 123_456).unwrap()
)
);
// ranges are inclusive, for a precise value, two identical values are returned
assert_eq!(
dt_value.range()?,
DateTimeRange::from_start_to_end_with_time_zone(
FixedOffset::east_opt(3600).unwrap()
.ymd_opt(2012, 12, 21).unwrap()
.and_hms_micro_opt(9, 30, 1, 123_456).unwrap(),
FixedOffset::east_opt(3600).unwrap()
.ymd_opt(2012, 12, 21).unwrap()
.and_hms_micro_opt(9, 30, 1, 123_456).unwrap()
)?
);
Sourcepub fn to_multi_datetime(&self) -> Result<Vec<DicomDateTime>, ConvertValueError>
pub fn to_multi_datetime(&self) -> Result<Vec<DicomDateTime>, ConvertValueError>
Retrieve the full sequence of DicomDateTime
s from this value.
Sourcepub fn to_date_range(&self) -> Result<DateRange, ConvertValueError>
pub fn to_date_range(&self) -> Result<DateRange, ConvertValueError>
Retrieve a single DateRange
from this value.
If the value is already represented as a DicomDate
, it is converted into DateRange
.
If the value is a string or sequence of strings,
the first string is decoded to obtain a DateRange
, potentially failing if the
string does not represent a valid DateRange
.
If the value is a sequence of U8 bytes, the bytes are
first interpreted as an ASCII character string.
§Example
use chrono::{NaiveDate};
use dicom_core::value::{DateRange};
let da_range = PrimitiveValue::from("2012-201305").to_date_range()?;
assert_eq!(
da_range.start(),
Some(&NaiveDate::from_ymd(2012, 1, 1))
);
assert_eq!(
da_range.end(),
Some(&NaiveDate::from_ymd(2013, 05, 31))
);
let range_from = PrimitiveValue::from("2012-").to_date_range()?;
assert!(range_from.end().is_none());
Sourcepub fn to_time_range(&self) -> Result<TimeRange, ConvertValueError>
pub fn to_time_range(&self) -> Result<TimeRange, ConvertValueError>
Retrieve a single TimeRange
from this value.
If the value is already represented as a DicomTime
, it is converted into a TimeRange
.
If the value is a string or sequence of strings,
the first string is decoded to obtain a TimeRange
, potentially failing if the
string does not represent a valid DateRange
.
If the value is a sequence of U8 bytes, the bytes are
first interpreted as an ASCII character string.
§Example
use chrono::{NaiveTime};
use dicom_core::value::{TimeRange};
let tm_range = PrimitiveValue::from("02-153000.123").to_time_range()?;
// null components default to zeros
assert_eq!(
tm_range.start(),
Some(&NaiveTime::from_hms(2, 0, 0))
);
// unspecified part of second fraction defaults to latest possible
assert_eq!(
tm_range.end(),
Some(&NaiveTime::from_hms_micro(15, 30, 0, 123_999))
);
let range_from = PrimitiveValue::from("01-").to_time_range()?;
assert!(range_from.end().is_none());
Sourcepub fn to_datetime_range(&self) -> Result<DateTimeRange, ConvertValueError>
pub fn to_datetime_range(&self) -> Result<DateTimeRange, ConvertValueError>
Retrieve a single DateTimeRange
from this value.
If the value is already represented as a DicomDateTime
, it is converted into DateTimeRange
.
If the value is a string or sequence of strings,
the first string is decoded to obtain a DateTimeRange
, potentially failing if the
string does not represent a valid DateTimeRange
.
If the value is a sequence of U8 bytes, the bytes are
first interpreted as an ASCII character string.
§Example
use chrono::{DateTime, NaiveDate, NaiveTime, NaiveDateTime, FixedOffset, TimeZone, Local};
use dicom_core::value::{DateTimeRange, PreciseDateTime};
// let's parse a text representation of a date-time range, where the lower bound is a microsecond
// precision value with a time-zone (east +05:00) and the upper bound is a minimum precision value
// with a time-zone
let dt_range = PrimitiveValue::from("19920101153020.123+0500-1993+0300").to_datetime_range()?;
// lower bound of range is parsed into a PreciseDateTimeResult::TimeZone variant
assert_eq!(
dt_range.start(),
Some(PreciseDateTime::TimeZone(
FixedOffset::east_opt(5*3600).unwrap().ymd_opt(1992, 1, 1).unwrap()
.and_hms_micro_opt(15, 30, 20, 123_000).unwrap()
)
)
);
// upper bound of range is parsed into a PreciseDateTimeResult::TimeZone variant
assert_eq!(
dt_range.end(),
Some(PreciseDateTime::TimeZone(
FixedOffset::east_opt(3*3600).unwrap().ymd_opt(1993, 12, 31).unwrap()
.and_hms_micro_opt(23, 59, 59, 999_999).unwrap()
)
)
);
let lower = PrimitiveValue::from("2012-").to_datetime_range()?;
// range has no upper bound
assert!(lower.end().is_none());
// One time-zone in a range is missing
let dt_range = PrimitiveValue::from("1992+0500-1993").to_datetime_range()?;
// It will be replaced with the local clock time-zone offset
// This can be customized with [to_datetime_range_custom()]
assert_eq!(
dt_range,
DateTimeRange::TimeZone{
start: Some(FixedOffset::east_opt(5*3600).unwrap()
.ymd_opt(1992, 1, 1).unwrap()
.and_hms_micro_opt(0, 0, 0, 0).unwrap()
),
end: Some(Local::now().offset()
.ymd_opt(1993, 12, 31).unwrap()
.and_hms_micro_opt(23, 59, 59, 999_999).unwrap()
)
}
);
Sourcepub fn to_datetime_range_custom<T: AmbiguousDtRangeParser>(
&self,
) -> Result<DateTimeRange, ConvertValueError>
pub fn to_datetime_range_custom<T: AmbiguousDtRangeParser>( &self, ) -> Result<DateTimeRange, ConvertValueError>
Retrieve a single DateTimeRange
from this value.
Use a custom ambiguous date-time range parser.
For full description see PrimitiveValue::to_datetime_range and AmbiguousDtRangeParser.
§Example
use dicom_core::value::range::{AmbiguousDtRangeParser, ToKnownTimeZone, IgnoreTimeZone, FailOnAmbiguousRange, DateTimeRange};
use chrono::{NaiveDate, NaiveTime, NaiveDateTime};
// The upper bound time-zone is missing
// the default behavior in this case is to use the local clock time-zone.
// But we want to use the known (parsed) time-zone from the lower bound instead.
let dt_range = PrimitiveValue::from("1992+0500-1993")
.to_datetime_range_custom::<ToKnownTimeZone>()?;
// values are in the same time-zone
assert_eq!(
dt_range.start().unwrap()
.as_datetime().unwrap()
.offset(),
dt_range.end().unwrap()
.as_datetime().unwrap()
.offset()
);
// ignore parsed time-zone, retrieve a time-zone naive range
let naive_range = PrimitiveValue::from("1992+0599-1993")
.to_datetime_range_custom::<IgnoreTimeZone>()?;
assert_eq!(
naive_range,
DateTimeRange::from_start_to_end(
NaiveDateTime::new(
NaiveDate::from_ymd_opt(1992, 1, 1).unwrap(),
NaiveTime::from_hms_micro_opt(0, 0, 0, 0).unwrap()
),
NaiveDateTime::new(
NaiveDate::from_ymd_opt(1993, 12, 31).unwrap(),
NaiveTime::from_hms_micro_opt(23, 59, 59, 999_999).unwrap()
)
).unwrap()
);
// always fail upon parsing an ambiguous DT range
assert!(
PrimitiveValue::from("1992+0599-1993")
.to_datetime_range_custom::<FailOnAmbiguousRange>().is_err()
);
Sourcepub fn to_person_name(&self) -> Result<PersonName<'_>, ConvertValueError>
pub fn to_person_name(&self) -> Result<PersonName<'_>, ConvertValueError>
Retrieve a single PersonName
from this value.
If the value is a string or sequence of strings,
the first string is split to obtain a PersonName
.
§Example
use dicom_core::value::PersonName;
let value = PrimitiveValue::from("Tooms^Victor^Eugene");
// PersonName contains borrowed values
let pn = value.to_person_name()?;
assert_eq!(pn.given(), Some("Victor"));
assert_eq!(pn.middle(), Some("Eugene"));
assert!(pn.prefix().is_none());
let value2 = PrimitiveValue::from(pn);
assert_eq!(value, value2);
Source§impl PrimitiveValue
impl PrimitiveValue
Per variant, strongly checked getters to DICOM values.
Conversions from one representation to another do not take place when using these methods.
Sourcepub fn string(&self) -> Result<&str, CastValueError>
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.
Sourcepub fn strings(&self) -> Result<&[String], CastValueError>
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.
Sourcepub fn tag(&self) -> Result<Tag, CastValueError>
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.
Get a sequence of values of the requested type without copying. An error is returned if the variant is not compatible.
Sourcepub fn date(&self) -> Result<DicomDate, CastValueError>
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.
Sourcepub fn dates(&self) -> Result<&[DicomDate], CastValueError>
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.
Sourcepub fn time(&self) -> Result<DicomTime, CastValueError>
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.
Sourcepub fn times(&self) -> Result<&[DicomTime], CastValueError>
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.
Sourcepub fn datetime(&self) -> Result<DicomDateTime, CastValueError>
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.
Sourcepub fn datetimes(&self) -> Result<&[DicomDateTime], CastValueError>
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.
Sourcepub fn uint8(&self) -> Result<u8, CastValueError>
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.
Sourcepub fn uint8_slice(&self) -> Result<&[u8], CastValueError>
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.
Sourcepub fn uint16(&self) -> Result<u16, CastValueError>
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.
Sourcepub fn uint16_slice(&self) -> Result<&[u16], CastValueError>
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.
Sourcepub fn int16(&self) -> Result<i16, CastValueError>
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.
Sourcepub fn int16_slice(&self) -> Result<&[i16], CastValueError>
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.
Sourcepub fn uint32(&self) -> Result<u32, CastValueError>
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.
Sourcepub fn uint32_slice(&self) -> Result<&[u32], CastValueError>
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.
Sourcepub fn int32(&self) -> Result<i32, CastValueError>
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.
Sourcepub fn int32_slice(&self) -> Result<&[i32], CastValueError>
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.
Sourcepub fn int64(&self) -> Result<i64, CastValueError>
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.
Sourcepub fn int64_slice(&self) -> Result<&[i64], CastValueError>
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.
Sourcepub fn uint64(&self) -> Result<u64, CastValueError>
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.
Sourcepub fn uint64_slice(&self) -> Result<&[u64], CastValueError>
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.
Sourcepub fn float32(&self) -> Result<f32, CastValueError>
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.
Sourcepub fn float32_slice(&self) -> Result<&[f32], CastValueError>
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.
Sourcepub fn float64(&self) -> Result<f64, CastValueError>
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.
Sourcepub fn float64_slice(&self) -> Result<&[f64], CastValueError>
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.
Sourcepub fn extend_str<T>(
&mut self,
strings: impl IntoIterator<Item = T>,
) -> Result<(), ModifyValueError>
pub fn extend_str<T>( &mut self, strings: impl IntoIterator<Item = T>, ) -> Result<(), ModifyValueError>
Extend a textual value by appending more strings to an existing text or empty value.
An error is returned if the current value is not textual.
§Example
use dicom_core::dicom_value;
let mut value = dicom_value!(Strs, ["Hello"]);
value.extend_str(["DICOM"])?;
assert_eq!(value.to_string(), "Hello\\DICOM");
Sourcepub fn extend_u16(
&mut self,
numbers: impl IntoIterator<Item = u16>,
) -> Result<(), ModifyValueError>
pub fn extend_u16( &mut self, numbers: impl IntoIterator<Item = u16>, ) -> Result<(), ModifyValueError>
Extend a value of numbers by appending 16-bit unsigned integers to an existing value.
The value may be empty or already contain numeric or textual values.
If the current value is textual, the numbers provided are converted to text. For the case of numeric values, the given numbers are converted to the current number type through casting, meaning that loss of precision may occur. If this is undesirable, read the current value and replace it manually.
An error is returned
if the current value is not compatible with the insertion of integers,
such as Tag
or Date
.
§Example
use dicom_core::dicom_value;
let mut value = dicom_value!(U16, [1, 2]);
value.extend_u16([5])?;
assert_eq!(value.to_multi_int::<u16>()?, vec![1, 2, 5]);
let mut value = dicom_value!(Strs, ["City"]);
value.extend_u16([17])?;
assert_eq!(value.to_string(), "City\\17");
Sourcepub fn extend_i16(
&mut self,
numbers: impl IntoIterator<Item = i16>,
) -> Result<(), ModifyValueError>
pub fn extend_i16( &mut self, numbers: impl IntoIterator<Item = i16>, ) -> Result<(), ModifyValueError>
Extend a value of numbers by appending 16-bit signed integers to an existing value.
The value may be empty or already contain numeric or textual values.
If the current value is textual, the numbers provided are converted to text. For the case of numeric values, the given numbers are converted to the current number type through casting, meaning that loss of precision may occur. If this is undesirable, read the current value and replace it manually.
An error is returned
if the current value is not compatible with the insertion of integers,
such as Tag
or Date
.
§Example
use dicom_core::dicom_value;
let mut value = dicom_value!(I16, [1, 2]);
value.extend_i16([-5])?;
assert_eq!(value.to_multi_int::<i16>()?, vec![1, 2, -5]);
let mut value = dicom_value!(Strs, ["City"]);
value.extend_i16([17])?;
assert_eq!(value.to_string(), "City\\17");
Sourcepub fn extend_i32(
&mut self,
numbers: impl IntoIterator<Item = i32>,
) -> Result<(), ModifyValueError>
pub fn extend_i32( &mut self, numbers: impl IntoIterator<Item = i32>, ) -> Result<(), ModifyValueError>
Extend a value of numbers by appending 32-bit signed integers to an existing value.
The value may be empty or already contain numeric or textual values.
If the current value is textual, the numbers provided are converted to text. For the case of numeric values, the given numbers are converted to the current number type through casting, meaning that loss of precision may occur. If this is undesirable, read the current value and replace it manually.
An error is returned
if the current value is not compatible with the insertion of integers,
such as Tag
or Date
.
§Example
use dicom_core::dicom_value;
let mut value = dicom_value!(I32, [1, 2]);
value.extend_i32([5])?;
assert_eq!(value.to_multi_int::<i32>()?, vec![1, 2, 5]);
let mut value = dicom_value!(Strs, ["City"]);
value.extend_i32([17])?;
assert_eq!(value.to_string(), "City\\17");
Sourcepub fn extend_u32(
&mut self,
numbers: impl IntoIterator<Item = u32>,
) -> Result<(), ModifyValueError>
pub fn extend_u32( &mut self, numbers: impl IntoIterator<Item = u32>, ) -> Result<(), ModifyValueError>
Extend a value of numbers by appending 32-bit unsigned integers to an existing value.
The value may be empty or already contain numeric or textual values.
If the current value is textual, the numbers provided are converted to text. For the case of numeric values, the given numbers are converted to the current number type through casting, meaning that loss of precision may occur. If this is undesirable, read the current value and replace it manually.
An error is returned
if the current value is not compatible with the insertion of integers,
such as Tag
or Date
.
§Example
use dicom_core::dicom_value;
let mut value = dicom_value!(U32, [1, 2]);
value.extend_u32([5])?;
assert_eq!(value.to_multi_int::<u32>()?, vec![1, 2, 5]);
let mut value = dicom_value!(Strs, ["City"]);
value.extend_u32([17])?;
assert_eq!(value.to_string(), "City\\17");
Sourcepub fn extend_f32(
&mut self,
numbers: impl IntoIterator<Item = f32>,
) -> Result<(), ModifyValueError>
pub fn extend_f32( &mut self, numbers: impl IntoIterator<Item = f32>, ) -> Result<(), ModifyValueError>
Extend a value of numbers by appending 32-bit floating point numbers to an existing value.
The value may be empty or already contain numeric or textual values.
If the current value is textual, the numbers provided are converted to text. For the case of numeric values, the given numbers are converted to the current number type through casting, meaning that loss of precision may occur. If this is undesirable, read the current value and replace it manually.
An error is returned
if the current value is not compatible with the insertion of integers,
such as Tag
or Date
.
§Example
use dicom_core::dicom_value;
let mut value = dicom_value!(F32, [1., 2.]);
value.extend_f32([5.])?;
assert_eq!(value.to_multi_float32()?, vec![1., 2., 5.]);
let mut value = dicom_value!(Strs, ["1.25"]);
value.extend_f32([0.5])?;
assert_eq!(value.to_string(), "1.25\\0.5");
Sourcepub fn extend_f64(
&mut self,
numbers: impl IntoIterator<Item = f64>,
) -> Result<(), ModifyValueError>
pub fn extend_f64( &mut self, numbers: impl IntoIterator<Item = f64>, ) -> Result<(), ModifyValueError>
Extend a value of numbers by appending 64-bit floating point numbers to an existing value.
The value may be empty or already contain numeric or textual values.
If the current value is textual, the numbers provided are converted to text. For the case of numeric values, the given numbers are converted to the current number type through casting, meaning that loss of precision may occur. If this is undesirable, read the current value and replace it manually.
An error is returned
if the current value is not compatible with the insertion of integers,
such as Tag
or Date
.
§Example
use dicom_core::dicom_value;
let mut value = dicom_value!(F64, [1., 2.]);
value.extend_f64([5.])?;
assert_eq!(value.to_multi_float64()?, vec![1., 2., 5.]);
let mut value = dicom_value!(Strs, ["1.25"]);
value.extend_f64([0.5])?;
assert_eq!(value.to_string(), "1.25\\0.5");
Sourcepub fn truncate(&mut self, limit: usize)
pub fn truncate(&mut self, limit: usize)
Shorten this value by removing trailing elements to fit the given limit.
Elements are counted by the number of individual value items
(note that bytes in a PrimitiveValue::U8
are treated as individual items).
Nothing is done if the value’s cardinality is already lower than or equal to the limit.
§Example
let mut value = dicom_value!(I32, [1, 2, 5]);
value.truncate(2);
assert_eq!(value.to_multi_int::<i32>()?, vec![1, 2]);
value.truncate(0);
assert_eq!(value.multiplicity(), 0);
Trait Implementations§
Source§impl Clone for PrimitiveValue
impl Clone for PrimitiveValue
Source§fn clone(&self) -> PrimitiveValue
fn clone(&self) -> PrimitiveValue
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for PrimitiveValue
impl Debug for PrimitiveValue
Source§impl DicomValueType for PrimitiveValue
impl DicomValueType for PrimitiveValue
Source§fn value_type(&self) -> ValueType
fn value_type(&self) -> ValueType
Source§fn cardinality(&self) -> usize
fn cardinality(&self) -> usize
Source§impl Display for PrimitiveValue
impl Display for PrimitiveValue
The output of this method is equivalent to calling the method to_str
Source§impl From<&[DicomDateTime; 1]> for PrimitiveValue
impl From<&[DicomDateTime; 1]> for PrimitiveValue
Source§fn from(value: &[DicomDateTime; 1]) -> Self
fn from(value: &[DicomDateTime; 1]) -> Self
Source§impl From<&[DicomDateTime; 2]> for PrimitiveValue
impl From<&[DicomDateTime; 2]> for PrimitiveValue
Source§fn from(value: &[DicomDateTime; 2]) -> Self
fn from(value: &[DicomDateTime; 2]) -> Self
Source§impl From<&[DicomDateTime; 3]> for PrimitiveValue
impl From<&[DicomDateTime; 3]> for PrimitiveValue
Source§fn from(value: &[DicomDateTime; 3]) -> Self
fn from(value: &[DicomDateTime; 3]) -> Self
Source§impl From<&[DicomDateTime; 4]> for PrimitiveValue
impl From<&[DicomDateTime; 4]> for PrimitiveValue
Source§fn from(value: &[DicomDateTime; 4]) -> Self
fn from(value: &[DicomDateTime; 4]) -> Self
Source§impl From<&[DicomDateTime; 5]> for PrimitiveValue
impl From<&[DicomDateTime; 5]> for PrimitiveValue
Source§fn from(value: &[DicomDateTime; 5]) -> Self
fn from(value: &[DicomDateTime; 5]) -> Self
Source§impl From<&[DicomDateTime; 6]> for PrimitiveValue
impl From<&[DicomDateTime; 6]> for PrimitiveValue
Source§fn from(value: &[DicomDateTime; 6]) -> Self
fn from(value: &[DicomDateTime; 6]) -> Self
Source§impl From<&[DicomDateTime; 7]> for PrimitiveValue
impl From<&[DicomDateTime; 7]> for PrimitiveValue
Source§fn from(value: &[DicomDateTime; 7]) -> Self
fn from(value: &[DicomDateTime; 7]) -> Self
Source§impl From<&[DicomDateTime; 8]> for PrimitiveValue
impl From<&[DicomDateTime; 8]> for PrimitiveValue
Source§fn from(value: &[DicomDateTime; 8]) -> Self
fn from(value: &[DicomDateTime; 8]) -> Self
Source§impl From<&[u8]> for PrimitiveValue
impl From<&[u8]> for PrimitiveValue
Source§impl From<&str> for PrimitiveValue
impl From<&str> for PrimitiveValue
Source§impl From<[DicomDateTime; 1]> for PrimitiveValue
impl From<[DicomDateTime; 1]> for PrimitiveValue
Source§fn from(value: [DicomDateTime; 1]) -> Self
fn from(value: [DicomDateTime; 1]) -> Self
Source§impl From<[DicomDateTime; 2]> for PrimitiveValue
impl From<[DicomDateTime; 2]> for PrimitiveValue
Source§fn from(value: [DicomDateTime; 2]) -> Self
fn from(value: [DicomDateTime; 2]) -> Self
Source§impl From<[DicomDateTime; 3]> for PrimitiveValue
impl From<[DicomDateTime; 3]> for PrimitiveValue
Source§fn from(value: [DicomDateTime; 3]) -> Self
fn from(value: [DicomDateTime; 3]) -> Self
Source§impl From<[DicomDateTime; 4]> for PrimitiveValue
impl From<[DicomDateTime; 4]> for PrimitiveValue
Source§fn from(value: [DicomDateTime; 4]) -> Self
fn from(value: [DicomDateTime; 4]) -> Self
Source§impl From<[DicomDateTime; 5]> for PrimitiveValue
impl From<[DicomDateTime; 5]> for PrimitiveValue
Source§fn from(value: [DicomDateTime; 5]) -> Self
fn from(value: [DicomDateTime; 5]) -> Self
Source§impl From<[DicomDateTime; 6]> for PrimitiveValue
impl From<[DicomDateTime; 6]> for PrimitiveValue
Source§fn from(value: [DicomDateTime; 6]) -> Self
fn from(value: [DicomDateTime; 6]) -> Self
Source§impl From<[DicomDateTime; 7]> for PrimitiveValue
impl From<[DicomDateTime; 7]> for PrimitiveValue
Source§fn from(value: [DicomDateTime; 7]) -> Self
fn from(value: [DicomDateTime; 7]) -> Self
Source§impl From<[DicomDateTime; 8]> for PrimitiveValue
impl From<[DicomDateTime; 8]> for PrimitiveValue
Source§fn from(value: [DicomDateTime; 8]) -> Self
fn from(value: [DicomDateTime; 8]) -> Self
Source§impl From<()> for PrimitiveValue
impl From<()> for PrimitiveValue
Source§impl From<DicomDate> for PrimitiveValue
impl From<DicomDate> for PrimitiveValue
Source§impl From<DicomDateTime> for PrimitiveValue
impl From<DicomDateTime> for PrimitiveValue
Source§fn from(value: DicomDateTime) -> Self
fn from(value: DicomDateTime) -> Self
Source§impl From<DicomTime> for PrimitiveValue
impl From<DicomTime> for PrimitiveValue
Source§impl From<PersonName<'_>> for PrimitiveValue
impl From<PersonName<'_>> for PrimitiveValue
Source§fn from(p: PersonName<'_>) -> Self
fn from(p: PersonName<'_>) -> Self
Source§impl<I, P> From<PrimitiveValue> for Value<I, P>
impl<I, P> From<PrimitiveValue> for Value<I, P>
Source§fn from(v: PrimitiveValue) -> Self
fn from(v: PrimitiveValue) -> Self
Source§impl From<String> for PrimitiveValue
impl From<String> for PrimitiveValue
Source§impl From<Tag> for PrimitiveValue
impl From<Tag> for PrimitiveValue
Source§impl From<f32> for PrimitiveValue
impl From<f32> for PrimitiveValue
Source§impl From<f64> for PrimitiveValue
impl From<f64> for PrimitiveValue
Source§impl From<i16> for PrimitiveValue
impl From<i16> for PrimitiveValue
Source§impl From<i32> for PrimitiveValue
impl From<i32> for PrimitiveValue
Source§impl From<i64> for PrimitiveValue
impl From<i64> for PrimitiveValue
Source§impl From<u16> for PrimitiveValue
impl From<u16> for PrimitiveValue
Source§impl From<u32> for PrimitiveValue
impl From<u32> for PrimitiveValue
Source§impl From<u64> for PrimitiveValue
impl From<u64> for PrimitiveValue
Source§impl From<u8> for PrimitiveValue
impl From<u8> for PrimitiveValue
Source§impl HasLength for PrimitiveValue
impl HasLength for PrimitiveValue
Source§impl PartialEq<&str> for PrimitiveValue
impl PartialEq<&str> for PrimitiveValue
Source§impl PartialEq<str> for PrimitiveValue
impl PartialEq<str> for PrimitiveValue
Source§impl PartialEq for PrimitiveValue
impl PartialEq for PrimitiveValue
Auto Trait Implementations§
impl Freeze for PrimitiveValue
impl RefUnwindSafe for PrimitiveValue
impl Send for PrimitiveValue
impl Sync for PrimitiveValue
impl Unpin for PrimitiveValue
impl UnwindSafe for PrimitiveValue
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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