Skip to content

Commit

Permalink
format all code
Browse files Browse the repository at this point in the history
  • Loading branch information
Enet4 committed Apr 25, 2024
1 parent 5a1d380 commit 8c5665d
Show file tree
Hide file tree
Showing 24 changed files with 459 additions and 291 deletions.
4 changes: 2 additions & 2 deletions core/src/dictionary/data_element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ pub enum VirtualVr {
/// ([`US`](VR::US)).
Xs,
/// Represents overlay data sample values.
///
///
/// It can be either [`OB`](VR::OB) or [`OW`](VR::OW).
Ox,
/// Represents pixel data sample value.
Expand Down Expand Up @@ -202,7 +202,7 @@ impl VirtualVr {
/// - [`Ox`](VirtualVr::Ox) is relaxed to [`OW`](VR::OW)
/// - [`Px`](VirtualVr::Px) is relaxed to [`OW`](VR::OW)
/// - [`Lt`](VirtualVr::Lt) is relaxed to [`OW`](VR::OW)
///
///
/// This method is ill-advised for uses where
/// the corresponding attribute is important.
pub fn relaxed(self) -> VR {
Expand Down
4 changes: 2 additions & 2 deletions core/src/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,15 +609,15 @@ pub enum AttributeAction {
PushF64(f64),
/// Truncate a value or a sequence to the given number of items,
/// removing extraneous items from the end of the list.
///
///
/// On primitive values, this truncates the value
/// 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.
///
///
/// Does nothing if the attribute does not exist
/// or the cardinality of the element is already lower than or equal to
/// the given size.
Expand Down
2 changes: 1 addition & 1 deletion core/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
//! use dicom_core::prelude::*;
//! ```
pub use crate::value::{AsRange as _, DicomDate, DicomDateTime, DicomTime};
pub use crate::{dicom_value, DataElement, DicomValue, Tag, VR};
pub use crate::{header::HasLength as _, DataDictionary as _};
pub use crate::value::{AsRange as _, DicomDate, DicomTime, DicomDateTime};
11 changes: 7 additions & 4 deletions core/src/value/deserialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ where
}

/// Retrieve a `chrono::DateTime` from the given text, while assuming the given UTC offset.
///
///
/// If a date/time component is missing, the operation fails.
/// Presence of the second fraction component `.FFFFFF` is mandatory with at
/// least one digit accuracy `.F` while missing digits default to zero.
Expand All @@ -340,7 +340,10 @@ where
/// because it is more flexible and resilient to missing components.
/// See also the implementation of [`FromStr`](std::str::FromStr)
/// for [`DicomDateTime`].
#[deprecated(since = "0.7.0", note = "Use `parse_datetime_partial()` then `to_precise_datetime()`")]
#[deprecated(
since = "0.7.0",
note = "Use `parse_datetime_partial()` then `to_precise_datetime()`"
)]
pub fn parse_datetime(buf: &[u8], dt_utc_offset: FixedOffset) -> Result<DateTime<FixedOffset>> {
let date = parse_date(buf)?;
let buf = &buf[8..];
Expand Down Expand Up @@ -380,12 +383,12 @@ pub fn parse_datetime(buf: &[u8], dt_utc_offset: FixedOffset) -> Result<DateTime

/// Decode the text from the byte slice into a [`DicomDateTime`] value,
/// which allows for missing Date / Time components.
///
///
/// This is the underlying implementation of [`FromStr`](std::str::FromStr)
/// for `DicomDateTime`.
///
/// # Example
///
///
/// ```
/// # use dicom_core::value::deserialize::parse_datetime_partial;
/// use dicom_core::value::{DicomDate, DicomDateTime, DicomTime, PreciseDateTime};
Expand Down
1 change: 0 additions & 1 deletion core/src/value/partial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,6 @@ impl PartialOrd for PreciseDateTime {
(PreciseDateTime::TimeZone(a), PreciseDateTime::TimeZone(b)) => a.partial_cmp(b),
_ => None,
}

}
}

Expand Down
26 changes: 10 additions & 16 deletions core/src/value/range.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
//! Handling of date, time, date-time ranges. Needed for range matching.
//! Parsing into ranges happens via partial precision structures (DicomDate, DicomTime,
//! DicomDatime) so ranges can handle null components in date, time, date-time values.
use chrono::{
DateTime, FixedOffset, Local, NaiveDate, NaiveDateTime, NaiveTime, TimeZone,
};
use chrono::{DateTime, FixedOffset, Local, NaiveDate, NaiveDateTime, NaiveTime, TimeZone};
use snafu::{Backtrace, OptionExt, ResultExt, Snafu};

use crate::value::deserialize::{
Expand Down Expand Up @@ -833,7 +831,7 @@ pub trait AmbiguousDtRangeParser {
/// This is the default behavior of the parser,
/// which helps attain compliance with the standard
/// as per [DICOM PS3.5 6.2](https://dicom.nema.org/medical/dicom/2023e/output/chtml/part05/sect_6.2.html):
///
///
/// > A Date Time Value without the optional suffix
/// > is interpreted to be in the local time zone of the application creating the Data Element,
/// > unless explicitly specified by the Timezone Offset From UTC (0008,0201).
Expand Down Expand Up @@ -1037,7 +1035,7 @@ impl AmbiguousDtRangeParser for IgnoreTimeZone {
/// This is the default behavior of the parser,
/// which helps attain compliance with the standard
/// as per [DICOM PS3.5 6.2](https://dicom.nema.org/medical/dicom/2023e/output/chtml/part05/sect_6.2.html):
///
///
/// > A Date Time Value without the optional suffix
/// > is interpreted to be in the local time zone of the application creating the Data Element,
/// > unless explicitly specified by the Timezone Offset From UTC (0008,0201).
Expand Down Expand Up @@ -1072,9 +1070,7 @@ pub fn parse_datetime_range_impl<T: AmbiguousDtRangeParser>(buf: &[u8]) -> Resul
let buf = &buf[1..];
match parse_datetime_partial(buf).context(ParseSnafu)?.latest()? {
PreciseDateTime::Naive(end) => Ok(DateTimeRange::from_end(end)),
PreciseDateTime::TimeZone(end_tz) => {
Ok(DateTimeRange::from_end_with_time_zone(end_tz))
}
PreciseDateTime::TimeZone(end_tz) => Ok(DateTimeRange::from_end_with_time_zone(end_tz)),
}
} else if buf[buf.len() - 1] == b'-' {
// ends with separator, range is Some-None
Expand Down Expand Up @@ -1113,14 +1109,12 @@ pub fn parse_datetime_range_impl<T: AmbiguousDtRangeParser>(buf: &[u8]) -> Resul
(Ok(s), Ok(e)) => {
//create a result here, to check for range inversion
let dtr = match (s.earliest()?, e.latest()?) {
(
PreciseDateTime::Naive(start),
PreciseDateTime::Naive(end),
) => DateTimeRange::from_start_to_end(start, end),
(
PreciseDateTime::TimeZone(start),
PreciseDateTime::TimeZone(end),
) => DateTimeRange::from_start_to_end_with_time_zone(start, end),
(PreciseDateTime::Naive(start), PreciseDateTime::Naive(end)) => {
DateTimeRange::from_start_to_end(start, end)
}
(PreciseDateTime::TimeZone(start), PreciseDateTime::TimeZone(end)) => {
DateTimeRange::from_start_to_end_with_time_zone(start, end)
}
(
// lower bound time-zone was missing
PreciseDateTime::Naive(start),
Expand Down
2 changes: 1 addition & 1 deletion core/src/value/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ mod test {
&mut data,
DicomDateTime::from_date_and_time(
DicomDate::from_ymd(1985, 12, 31).unwrap(),
DicomTime::from_hms_micro(23, 59, 48, 123_456).unwrap()
DicomTime::from_hms_micro(23, 59, 48, 123_456).unwrap(),
)
.unwrap(),
)
Expand Down
8 changes: 2 additions & 6 deletions encoding/src/adapters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,7 @@ pub trait PixelDataReader {
/// (so that images in _MONOCHROME1_ continue to be in _MONOCHROME1_
/// and images in _MONOCHROME2_ continue to be in _MONOCHROME2_).
fn decode(&self, src: &dyn PixelDataObject, dst: &mut Vec<u8>) -> DecodeResult<()> {
let frames = src
.number_of_frames()
.unwrap_or(1);
let frames = src.number_of_frames().unwrap_or(1);
for frame in 0..frames {
self.decode_frame(src, frame, dst)?;
}
Expand Down Expand Up @@ -316,9 +314,7 @@ pub trait PixelDataWriter {
dst: &mut Vec<Vec<u8>>,
offset_table: &mut Vec<u32>,
) -> EncodeResult<Vec<AttributeOp>> {
let frames = src
.number_of_frames()
.unwrap_or(1);
let frames = src.number_of_frames().unwrap_or(1);
let mut out = Vec::new();
for frame in 0..frames {
let mut frame_data = Vec::new();
Expand Down
4 changes: 2 additions & 2 deletions encoding/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@ where
/// A descriptor for a specific character set,
/// taking part in text encoding and decoding
/// as per [PS3.5 ch 6 6.1](https://dicom.nema.org/medical/dicom/2023e/output/chtml/part05/chapter_6.html#sect_6.1).
///
///
/// # Example
///
/// Use [`from_code`](SpecificCharacterSet::from_code)
/// or one of the associated constants to create a character set.
/// From there, use the [`TextCodec`] trait to encode and decode text.
///
///
/// ```
/// use dicom_encoding::text::{SpecificCharacterSet, TextCodec};
///
Expand Down
8 changes: 3 additions & 5 deletions fromimage/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,10 @@ fn main() {
// recover implementation class UID and version name from base object
if retain_implementation {
let implementation_class_uid = &obj.meta().implementation_class_uid;
meta_builder = meta_builder
.implementation_class_uid(implementation_class_uid);

meta_builder = meta_builder.implementation_class_uid(implementation_class_uid);

if let Some(implementation_version_name) = obj.meta().implementation_version_name.as_ref() {
meta_builder = meta_builder
.implementation_version_name(implementation_version_name);
meta_builder = meta_builder.implementation_version_name(implementation_version_name);
}
}

Expand Down
5 changes: 4 additions & 1 deletion json/src/de/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ where
},
) = e;
if bulk_data_uri.is_some() {
tracing::warn!("bulk data URI is not supported for InMemDicomObject; skipping {}", tag);
tracing::warn!(
"bulk data URI is not supported for InMemDicomObject; skipping {}",
tag
);
} else {
obj.put(DataElement::new(tag, vr, value));
}
Expand Down
4 changes: 2 additions & 2 deletions object/src/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ where
/// or the private element is not found.
///
/// For more info, see the [DICOM standard section on private elements][1].
///
///
/// [1]: https://dicom.nema.org/medical/dicom/2024a/output/chtml/part05/sect_7.8.html
///
/// ## Example
Expand Down Expand Up @@ -800,7 +800,7 @@ where
/// An error is returned if there is no space left in the group.
///
/// For more info, see the [DICOM standard section on private elements][1].
///
///
/// [1]: https://dicom.nema.org/medical/dicom/2024a/output/chtml/part05/sect_7.8.html
///
/// ## Example
Expand Down
6 changes: 5 additions & 1 deletion parser/src/dataset/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,11 @@ where
ts_uid: ts.uid(),
ts_alias: ts.name(),
})?;
Ok(DataSetWriter::new_with_codec(to, encoder, SpecificCharacterSet::default()))
Ok(DataSetWriter::new_with_codec(
to,
encoder,
SpecificCharacterSet::default(),
))
}

/// Create a new data set writer
Expand Down
Loading

0 comments on commit 8c5665d

Please sign in to comment.