Skip to content

Commit

Permalink
Merge pull request #531 from Enet4/chore/clippy/2024-07
Browse files Browse the repository at this point in the history
Lint (2024-07)
  • Loading branch information
Enet4 authored Jul 6, 2024
2 parents a43f3c8 + 79a1c6b commit 7b6f976
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 76 deletions.
7 changes: 3 additions & 4 deletions core/src/value/deserialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,9 @@ pub enum Error {

type Result<T, E = Error> = std::result::Result<T, E>;

/** Decode a single DICOM Date (DA) into a `chrono::NaiveDate` value.
* As per standard, a full 8 byte representation (YYYYMMDD) is required,
otherwise, the operation fails.
*/
/// Decode a single DICOM Date (DA) into a `chrono::NaiveDate` value.
/// As per standard, a full 8 byte representation (YYYYMMDD) is required,
/// otherwise, the operation fails.
pub fn parse_date(buf: &[u8]) -> Result<NaiveDate> {
match buf.len() {
4 => IncompleteValueSnafu {
Expand Down
1 change: 1 addition & 0 deletions core/src/value/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,7 @@ impl AmbiguousDtRangeParser for IgnoreTimeZone {
/// - two very short date-times in the form of YYYY are presented (YYYY-YYYY)
/// - both YYYY values can be exchanged for a valid west UTC offset, meaning year <= 1200 e.g. (1000-1100)
/// - only one west UTC offset is presented. e.g. (1000-1100-0100)
///
/// In such cases, two '-' characters are present and the parser will favor the first one as a range separator,
/// if it produces a valid `DateTimeRange`. Otherwise, it tries the second one.
pub fn parse_datetime_range(buf: &[u8]) -> Result<DateTimeRange> {
Expand Down
4 changes: 2 additions & 2 deletions encoding/src/transfer_syntax/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,10 +600,10 @@ impl<D, R, W> TransferSyntax<D, R, W> {
/// and the given writer type (this method is not object safe).
/// Can yield none if encoding is not supported. The resulting encoder does not
/// consider pixel data encapsulation or data set compression rules.
pub fn encoder_for<'w, T: 'w>(&self) -> Option<DynEncoder<'w, T>>
pub fn encoder_for<'w, T>(&self) -> Option<DynEncoder<'w, T>>
where
Self: Sized,
T: ?Sized + Write,
T: ?Sized + Write + 'w,
{
match (self.byte_order, self.explicit_vr) {
(Endianness::Little, false) => Some(Box::new(EncoderFor::new(
Expand Down
2 changes: 1 addition & 1 deletion json/src/ser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub fn to_value<T>(data: T) -> Result<serde_json::Value, serde_json::Error>
where
DicomJson<T>: From<T> + Serialize,
{
serde_json::to_value(&DicomJson::from(data))
serde_json::to_value(DicomJson::from(data))
}

/// Serialize a piece of DICOM data to a vector of bytes.
Expand Down
24 changes: 10 additions & 14 deletions object/src/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,7 @@ where
/// is insufficient. Otherwise, please use [`open_file_with_dict`] instead.
///
/// [`open_file_with_dict`]: #method.open_file_with_dict
pub fn open_file_with<P: AsRef<Path>, R>(
path: P,
dict: D,
ts_index: R,
) -> Result<Self, ReadError>
pub fn open_file_with<P, R>(path: P, dict: D, ts_index: R) -> Result<Self, ReadError>
where
P: AsRef<Path>,
R: TransferSyntaxIndex,
Expand Down Expand Up @@ -341,7 +337,7 @@ where
Ok(ReadPreamble::Auto)
}

pub(crate) fn open_file_with_all_options<P: AsRef<Path>, R>(
pub(crate) fn open_file_with_all_options<P, R>(
path: P,
dict: D,
ts_index: R,
Expand Down Expand Up @@ -420,23 +416,23 @@ where
/// is insufficient. Otherwise, please use [`from_reader_with_dict`] instead.
///
/// [`from_reader_with_dict`]: #method.from_reader_with_dict
pub fn from_reader_with<'s, S: 's, R>(src: S, dict: D, ts_index: R) -> Result<Self, ReadError>
pub fn from_reader_with<'s, S, R>(src: S, dict: D, ts_index: R) -> Result<Self, ReadError>
where
S: Read,
S: Read + 's,
R: TransferSyntaxIndex,
{
Self::from_reader_with_all_options(src, dict, ts_index, None, ReadPreamble::Auto)
}

pub(crate) fn from_reader_with_all_options<'s, S: 's, R>(
pub(crate) fn from_reader_with_all_options<'s, S, R>(
src: S,
dict: D,
ts_index: R,
read_until: Option<Tag>,
mut read_preamble: ReadPreamble,
) -> Result<Self, ReadError>
where
S: Read,
S: Read + 's,
R: TransferSyntaxIndex,
{
let mut file = BufReader::new(src);
Expand Down Expand Up @@ -1814,15 +1810,15 @@ where
// private methods

/// Build an object by consuming a data set parser.
fn build_object<I: ?Sized>(
fn build_object<I>(
dataset: &mut I,
dict: D,
in_item: bool,
len: Length,
read_until: Option<Tag>,
) -> Result<Self, ReadError>
where
I: Iterator<Item = ParserResult<DataToken>>,
I: ?Sized + Iterator<Item = ParserResult<DataToken>>,
{
let mut entries: BTreeMap<Tag, InMemElement<D>> = BTreeMap::new();
// perform a structured parsing of incoming tokens
Expand Down Expand Up @@ -1954,14 +1950,14 @@ where
}

/// Build a DICOM sequence by consuming a data set parser.
fn build_sequence<I: ?Sized>(
fn build_sequence<I>(
_tag: Tag,
_len: Length,
dataset: &mut I,
dict: &D,
) -> Result<C<InMemDicomObject<D>>, ReadError>
where
I: Iterator<Item = ParserResult<DataToken>>,
I: ?Sized + Iterator<Item = ParserResult<DataToken>>,
{
let mut items: C<_> = SmallVec::new();
while let Some(token) = dataset.next() {
Expand Down
4 changes: 2 additions & 2 deletions object/src/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ pub struct FileMetaTable {
}

/// Utility function for reading the body of the DICOM element as a UID.
fn read_str_body<'s, S: 's, T>(source: &'s mut S, text: &T, len: u32) -> Result<String>
fn read_str_body<'s, S, T>(source: &'s mut S, text: &T, len: u32) -> Result<String>
where
S: Read,
S: Read + 's,
T: TextCodec,
{
let mut v = Vec::new();
Expand Down
2 changes: 1 addition & 1 deletion parser/src/stateful/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ where
/// (always with zeros)
/// to ensure that the encoded value has an even number of bytes.
pub fn write_bytes(&mut self, bytes: &[u8]) -> Result<()> {
debug_assert!(bytes.len() < u32::max_value() as usize);
debug_assert!(bytes.len() < u32::MAX as usize);
self.to.write_all(bytes).context(WriteValueDataSnafu {
position: self.bytes_written,
})?;
Expand Down
30 changes: 10 additions & 20 deletions pixeldata/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1172,11 +1172,9 @@ impl DecodedPixelData<'_> {
/// # Ok(())
/// # }
/// ```
pub fn to_vec<T: 'static>(&self) -> Result<Vec<T>>
pub fn to_vec<T>(&self) -> Result<Vec<T>>
where
T: NumCast,
T: Send + Sync,
T: Copy,
T: NumCast + Send + Sync + Copy + 'static,
{
let mut res: Vec<T> = Vec::new();
for frame in 0..self.number_of_frames {
Expand All @@ -1202,11 +1200,9 @@ impl DecodedPixelData<'_> {
/// which transformations should be done to the pixel data
/// (primarily Modality LUT function and VOI LUT function).
/// By default, only the Modality LUT function is applied.
pub fn to_vec_with_options<T: 'static>(&self, options: &ConvertOptions) -> Result<Vec<T>>
pub fn to_vec_with_options<T>(&self, options: &ConvertOptions) -> Result<Vec<T>>
where
T: NumCast,
T: Send + Sync,
T: Copy,
T: NumCast + Send + Sync + Copy + 'static,
{
let mut res: Vec<T> = Vec::new();
for frame in 0..self.number_of_frames {
Expand All @@ -1232,11 +1228,9 @@ impl DecodedPixelData<'_> {
/// applies only the Modality LUT function.
/// To change this behavior,
/// see [`to_vec_frame_with_options`](Self::to_vec_frame_with_options).
pub fn to_vec_frame<T: 'static>(&self, frame: u32) -> Result<Vec<T>>
pub fn to_vec_frame<T>(&self, frame: u32) -> Result<Vec<T>>
where
T: NumCast,
T: Send + Sync,
T: Copy,
T: NumCast + Send + Sync + Copy + 'static,
{
self.convert_pixel_slice(self.frame_data(frame)?, frame, &Default::default())
}
Expand Down Expand Up @@ -1279,29 +1273,25 @@ impl DecodedPixelData<'_> {
/// # Ok(())
/// # }
/// ```
pub fn to_vec_frame_with_options<T: 'static>(
pub fn to_vec_frame_with_options<T>(
&self,
frame: u32,
options: &ConvertOptions,
) -> Result<Vec<T>>
where
T: NumCast,
T: Send + Sync,
T: Copy,
T: NumCast + Send + Sync + Copy + 'static,
{
self.convert_pixel_slice(self.frame_data(frame)?, frame, options)
}

fn convert_pixel_slice<T: 'static>(
fn convert_pixel_slice<T>(
&self,
data: &[u8],
frame: u32,
options: &ConvertOptions,
) -> Result<Vec<T>>
where
T: NumCast,
T: Send + Sync,
T: Copy,
T: NumCast + Send + Sync + Copy + 'static,
{
let ConvertOptions {
modality_lut,
Expand Down
12 changes: 6 additions & 6 deletions pixeldata/src/lut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,9 @@ where
///
/// The highest bits from the sample after `bits_stored` bits are discarded,
/// thus silently ignoring them.
pub fn get<I: 'static>(&self, sample_value: I) -> T
pub fn get<I>(&self, sample_value: I) -> T
where
I: Copy,
I: Copy + 'static,
I: Into<u32>,
{
let val = sample_value.into() & self.sample_mask;
Expand All @@ -300,12 +300,12 @@ where

/// Adapts an iterator of pixel data sample values
/// to an iterator of transformed values.
pub fn map_iter<'a, I: 'static>(
pub fn map_iter<'a, I>(
&'a self,
iter: impl IntoIterator<Item = I> + 'a,
) -> impl Iterator<Item = T> + 'a
where
I: Copy,
I: Copy + 'static,
I: Into<u32>,
{
iter.into_iter().map(move |i| self.get(i))
Expand All @@ -314,12 +314,12 @@ where
/// Adapts a parallel iterator of pixel data sample values
/// to a parallel iterator of transformed values.
#[cfg(feature = "rayon")]
pub fn map_par_iter<'a, I: 'static>(
pub fn map_par_iter<'a, I>(
&'a self,
iter: impl ParallelIterator<Item = I> + 'a,
) -> impl ParallelIterator<Item = T> + 'a
where
I: Copy,
I: Copy + 'static,
I: Into<u32>,
{
iter.map(move |i| self.get(i))
Expand Down
42 changes: 23 additions & 19 deletions toimage/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ struct App {
#[arg(short = 'F', long = "frame", default_value = "0")]
frame_number: u32,

#[clap(flatten)]
image_options: ImageOptions,

/// Print more information about the image and the output file
#[arg(short = 'v', long = "verbose")]
verbose: bool,
}

/// Options related to image output and conversion steps
#[derive(Debug, Copy, Clone, Parser)]
struct ImageOptions {
/// Force output bit depth to 8 bits per sample
#[arg(long = "8bit", conflicts_with = "force_16bit")]
force_8bit: bool,
Expand All @@ -55,12 +66,9 @@ struct App {
conflicts_with = "force_16bit"
)]
unwrap: bool,

/// Print more information about the image and the output file
#[arg(short = 'v', long = "verbose")]
verbose: bool,
}


#[derive(Debug, Snafu)]
enum Error {
#[snafu(display("could not read DICOM file {}", path.display()))]
Expand Down Expand Up @@ -156,9 +164,7 @@ fn run(args: App) -> Result<(), Error> {
output,
ext,
frame_number,
force_8bit,
force_16bit,
unwrap,
image_options,
verbose,
} = args;

Expand All @@ -185,9 +191,7 @@ fn run(args: App) -> Result<(), Error> {
outdir.clone(),
ext.clone(),
frame_number,
force_8bit,
force_16bit,
unwrap,
image_options,
verbose,
)
.unwrap();
Expand All @@ -204,9 +208,7 @@ fn run(args: App) -> Result<(), Error> {
outdir,
ext,
frame_number,
force_8bit,
force_16bit,
unwrap,
image_options,
verbose,
)?;
}
Expand All @@ -223,9 +225,7 @@ fn run(args: App) -> Result<(), Error> {
outdir.clone(),
ext.clone(),
frame_number,
force_8bit,
force_16bit,
unwrap,
image_options,
verbose,
)
.unwrap();
Expand All @@ -242,11 +242,15 @@ fn convert_single_file(
outdir: Option<PathBuf>,
ext: Option<String>,
frame_number: u32,
force_8bit: bool,
force_16bit: bool,
unwrap: bool,
image_options: ImageOptions,
verbose: bool,
) -> Result<(), Error> {
let ImageOptions {
force_8bit,
force_16bit,
unwrap,
} = image_options;

// check if there is a .dcm extension, otherwise, add it
if output.extension() != Some("dcm".as_ref()) && !output_is_set {
let pathstr = output.to_str().unwrap();
Expand Down
14 changes: 7 additions & 7 deletions ul/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
//! and service class providers (SCPs).
//!
//! - The [`address`] module
//! provides an abstraction for working with compound addresses
//! referring to application entities in a network.
//! provides an abstraction for working with compound addresses
//! referring to application entities in a network.
//! - The [`pdu`] module
//! provides data structures representing _protocol data units_,
//! which are passed around as part of the DICOM network communication support.
//! provides data structures representing _protocol data units_,
//! which are passed around as part of the DICOM network communication support.
//! - The [`association`] module
//! comprises abstractions for establishing and negotiating associations
//! between application entities,
//! via the upper layer protocol by TCP.
//! comprises abstractions for establishing and negotiating associations
//! between application entities,
//! via the upper layer protocol by TCP.

pub mod address;
pub mod association;
Expand Down

0 comments on commit 7b6f976

Please sign in to comment.