From 9997f9c4baaa9a1d3375ee63cd21278c1152c6d7 Mon Sep 17 00:00:00 2001 From: Eduardo Pinho Date: Tue, 19 Mar 2024 19:23:07 +0000 Subject: [PATCH 01/12] [core] Tweak qualification of impl Add --- core/src/header.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/header.rs b/core/src/header.rs index bcc254b68..d30252dfe 100644 --- a/core/src/header.rs +++ b/core/src/header.rs @@ -1217,7 +1217,7 @@ impl PartialOrd for Length { } } -impl ::std::ops::Add for Length { +impl std::ops::Add for Length { type Output = Self; fn add(self, rhs: Length) -> Self::Output { @@ -1235,7 +1235,7 @@ impl ::std::ops::Add for Length { } } -impl ::std::ops::Add for Length { +impl std::ops::Add for Length { type Output = Self; fn add(self, rhs: i32) -> Self::Output { From 79ffb5431e49ea3d46e30d8f7cc76838f24c14be Mon Sep 17 00:00:00 2001 From: Eduardo Pinho Date: Tue, 19 Mar 2024 19:25:03 +0000 Subject: [PATCH 02/12] [core] Remove unused variant of ParseSelectorErrorInner --- core/src/dictionary/data_element.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/core/src/dictionary/data_element.rs b/core/src/dictionary/data_element.rs index a467519c8..e94646aac 100644 --- a/core/src/dictionary/data_element.rs +++ b/core/src/dictionary/data_element.rs @@ -152,8 +152,6 @@ enum ParseSelectorErrorInner { ParseKey, /// invalid item index, should be an unsigned integer ParseItemIndex, - /// intermediate selector step should select a sequence item - ParseItem, /// last selector step should select a plain tag ParseLeaf, } From 6e8cc8109b8283d8129aedc7aff4b85de650cf89 Mon Sep 17 00:00:00 2001 From: Eduardo Pinho Date: Tue, 19 Mar 2024 19:54:59 +0000 Subject: [PATCH 03/12] [encode] rearrange imports --- encoding/src/decode/explicit_be.rs | 11 +++- encoding/src/decode/explicit_le.rs | 6 +- encoding/src/decode/implicit_le.rs | 6 +- encoding/src/decode/mod.rs | 102 ++++++++++++++--------------- encoding/src/encode/explicit_be.rs | 9 ++- encoding/src/encode/explicit_le.rs | 5 +- encoding/src/encode/implicit_le.rs | 6 +- encoding/src/encode/mod.rs | 8 +-- 8 files changed, 88 insertions(+), 65 deletions(-) diff --git a/encoding/src/decode/explicit_be.rs b/encoding/src/decode/explicit_be.rs index ce59640fc..3237cebef 100644 --- a/encoding/src/decode/explicit_be.rs +++ b/encoding/src/decode/explicit_be.rs @@ -1,8 +1,11 @@ //! Explicit VR Big Endian syntax transfer implementation. use crate::decode::basic::BigEndianBasicDecoder; -use crate::decode::*; -use crate::decode::{BasicDecode, Decode, DecodeFrom}; +use crate::decode::{ + BadSequenceHeaderSnafu, BasicDecode, Decode, DecodeFrom, ReadHeaderTagSnafu, + ReadItemHeaderSnafu, ReadItemLengthSnafu, ReadLengthSnafu, ReadReservedSnafu, ReadTagSnafu, + ReadVrSnafu, Result, +}; use byteordered::byteorder::{BigEndian, ByteOrder}; use dicom_core::header::{DataElementHeader, Length, SequenceItemHeader}; use dicom_core::{Tag, VR}; @@ -65,7 +68,9 @@ impl Decode for ExplicitVRBigEndianDecoder { } _ => { // read 2 bytes for the data length - source.read_exact(&mut buf[0..2]).context(ReadLengthSnafu)?; + source + .read_exact(&mut buf[0..2]) + .context(ReadItemLengthSnafu)?; bytes_read = 8; u32::from(BigEndian::read_u16(&buf[0..2])) } diff --git a/encoding/src/decode/explicit_le.rs b/encoding/src/decode/explicit_le.rs index ab821b1b2..aa6830e57 100644 --- a/encoding/src/decode/explicit_le.rs +++ b/encoding/src/decode/explicit_le.rs @@ -1,7 +1,11 @@ //! Explicit VR Little Endian syntax transfer implementation use crate::decode::basic::LittleEndianBasicDecoder; -use crate::decode::*; +use crate::decode::{ + BadSequenceHeaderSnafu, BasicDecode, Decode, DecodeFrom, ReadHeaderTagSnafu, + ReadItemHeaderSnafu, ReadItemLengthSnafu, ReadLengthSnafu, ReadReservedSnafu, ReadTagSnafu, + ReadVrSnafu, Result, +}; use byteordered::byteorder::{ByteOrder, LittleEndian}; use dicom_core::header::{DataElementHeader, Length, SequenceItemHeader}; use dicom_core::{Tag, VR}; diff --git a/encoding/src/decode/implicit_le.rs b/encoding/src/decode/implicit_le.rs index fb6675211..af6bf9dfc 100644 --- a/encoding/src/decode/implicit_le.rs +++ b/encoding/src/decode/implicit_le.rs @@ -1,7 +1,11 @@ //! Implicit VR Big Endian syntax transfer implementation use crate::decode::basic::LittleEndianBasicDecoder; -use crate::decode::*; +use crate::decode::{ + BadSequenceHeaderSnafu, BasicDecode, DecodeFrom, ReadHeaderTagSnafu, ReadLengthSnafu, + ReadTagSnafu, Result, +}; +use crate::Decode; use byteordered::byteorder::{ByteOrder, LittleEndian}; use dicom_core::dictionary::{DataDictionary, DataDictionaryEntry}; use dicom_core::header::{DataElementHeader, Length, SequenceItemHeader}; diff --git a/encoding/src/decode/mod.rs b/encoding/src/decode/mod.rs index aa7e00aaf..3dc7db730 100644 --- a/encoding/src/decode/mod.rs +++ b/encoding/src/decode/mod.rs @@ -90,13 +90,13 @@ pub trait BasicDecode { fn endianness(&self) -> Endianness; /// Decode an unsigned short value from the given source. - fn decode_us(&self, source: S) -> std::io::Result + fn decode_us(&self, source: S) -> io::Result where S: Read; /// Decode a sequence of unsigned shorts value from the given source /// into the given destination. - fn decode_us_into(&self, mut source: S, dst: &mut [u16]) -> std::io::Result<()> + fn decode_us_into(&self, mut source: S, dst: &mut [u16]) -> io::Result<()> where S: Read, { @@ -108,13 +108,13 @@ pub trait BasicDecode { } /// Decode an unsigned long value from the given source. - fn decode_ul(&self, source: S) -> std::io::Result + fn decode_ul(&self, source: S) -> io::Result where S: Read; /// Decode a sequence of unsigned long values from the given source /// into the given destination. - fn decode_ul_into(&self, mut source: S, dst: &mut [u32]) -> std::io::Result<()> + fn decode_ul_into(&self, mut source: S, dst: &mut [u32]) -> io::Result<()> where S: Read, { @@ -126,13 +126,13 @@ pub trait BasicDecode { } /// Decode an unsigned very long value from the given source. - fn decode_uv(&self, source: S) -> std::io::Result + fn decode_uv(&self, source: S) -> io::Result where S: Read; /// Decode a sequence of unsigned very long values from the given source /// into the given destination. - fn decode_uv_into(&self, mut source: S, dst: &mut [u64]) -> std::io::Result<()> + fn decode_uv_into(&self, mut source: S, dst: &mut [u64]) -> io::Result<()> where S: Read, { @@ -144,13 +144,13 @@ pub trait BasicDecode { } /// Decode a signed short value from the given source. - fn decode_ss(&self, source: S) -> std::io::Result + fn decode_ss(&self, source: S) -> io::Result where S: Read; /// Decode a sequence of signed short values from the given source /// into the given destination. - fn decode_ss_into(&self, mut source: S, dst: &mut [i16]) -> std::io::Result<()> + fn decode_ss_into(&self, mut source: S, dst: &mut [i16]) -> io::Result<()> where S: Read, { @@ -162,13 +162,13 @@ pub trait BasicDecode { } /// Decode a signed long value from the given source. - fn decode_sl(&self, source: S) -> std::io::Result + fn decode_sl(&self, source: S) -> io::Result where S: Read; /// Decode a sequence of signed long values from the given source /// into the given destination. - fn decode_sl_into(&self, mut source: S, dst: &mut [i32]) -> std::io::Result<()> + fn decode_sl_into(&self, mut source: S, dst: &mut [i32]) -> io::Result<()> where S: Read, { @@ -180,13 +180,13 @@ pub trait BasicDecode { } /// Decode a signed very long value from the given source. - fn decode_sv(&self, source: S) -> std::io::Result + fn decode_sv(&self, source: S) -> io::Result where S: Read; /// Decode a sequence of signed very long values from the given source /// into the given destination. - fn decode_sv_into(&self, mut source: S, dst: &mut [i64]) -> std::io::Result<()> + fn decode_sv_into(&self, mut source: S, dst: &mut [i64]) -> io::Result<()> where S: Read, { @@ -198,13 +198,13 @@ pub trait BasicDecode { } /// Decode a single precision float value from the given source. - fn decode_fl(&self, source: S) -> std::io::Result + fn decode_fl(&self, source: S) -> io::Result where S: Read; /// Decode a sequence of single precision float values from the given source /// into the given destination. - fn decode_fl_into(&self, mut source: S, dst: &mut [f32]) -> std::io::Result<()> + fn decode_fl_into(&self, mut source: S, dst: &mut [f32]) -> io::Result<()> where S: Read, { @@ -216,13 +216,13 @@ pub trait BasicDecode { } /// Decode a double precision float value from the given source. - fn decode_fd(&self, source: S) -> std::io::Result + fn decode_fd(&self, source: S) -> io::Result where S: Read; /// Decode a sequence of double precision float values from the given source /// into the given destination. - fn decode_fd_into(&self, mut source: S, dst: &mut [f64]) -> std::io::Result<()> + fn decode_fd_into(&self, mut source: S, dst: &mut [f64]) -> io::Result<()> where S: Read, { @@ -234,7 +234,7 @@ pub trait BasicDecode { } /// Decode a DICOM attribute tag from the given source. - fn decode_tag(&self, mut source: S) -> std::io::Result + fn decode_tag(&self, mut source: S) -> io::Result where S: Read, { @@ -252,119 +252,119 @@ where (**self).endianness() } - fn decode_us(&self, source: S) -> std::io::Result + fn decode_us(&self, source: S) -> io::Result where S: Read, { (**self).decode_us(source) } - fn decode_us_into(&self, source: S, dst: &mut [u16]) -> std::io::Result<()> + fn decode_us_into(&self, source: S, dst: &mut [u16]) -> io::Result<()> where S: Read, { (**self).decode_us_into(source, dst) } - fn decode_ul(&self, source: S) -> std::io::Result + fn decode_ul(&self, source: S) -> io::Result where S: Read, { (**self).decode_ul(source) } - fn decode_ul_into(&self, source: S, dst: &mut [u32]) -> std::io::Result<()> + fn decode_ul_into(&self, source: S, dst: &mut [u32]) -> io::Result<()> where S: Read, { (**self).decode_ul_into(source, dst) } - fn decode_uv(&self, source: S) -> std::io::Result + fn decode_uv(&self, source: S) -> io::Result where S: Read, { (**self).decode_uv(source) } - fn decode_uv_into(&self, source: S, dst: &mut [u64]) -> std::io::Result<()> + fn decode_uv_into(&self, source: S, dst: &mut [u64]) -> io::Result<()> where S: Read, { (**self).decode_uv_into(source, dst) } - fn decode_ss(&self, source: S) -> std::io::Result + fn decode_ss(&self, source: S) -> io::Result where S: Read, { (**self).decode_ss(source) } - fn decode_ss_into(&self, source: S, dst: &mut [i16]) -> std::io::Result<()> + fn decode_ss_into(&self, source: S, dst: &mut [i16]) -> io::Result<()> where S: Read, { (**self).decode_ss_into(source, dst) } - fn decode_sl(&self, source: S) -> std::io::Result + fn decode_sl(&self, source: S) -> io::Result where S: Read, { (**self).decode_sl(source) } - fn decode_sl_into(&self, source: S, dst: &mut [i32]) -> std::io::Result<()> + fn decode_sl_into(&self, source: S, dst: &mut [i32]) -> io::Result<()> where S: Read, { (**self).decode_sl_into(source, dst) } - fn decode_sv(&self, source: S) -> std::io::Result + fn decode_sv(&self, source: S) -> io::Result where S: Read, { (**self).decode_sv(source) } - fn decode_sv_into(&self, source: S, dst: &mut [i64]) -> std::io::Result<()> + fn decode_sv_into(&self, source: S, dst: &mut [i64]) -> io::Result<()> where S: Read, { (**self).decode_sv_into(source, dst) } - fn decode_fl(&self, source: S) -> std::io::Result + fn decode_fl(&self, source: S) -> io::Result where S: Read, { (**self).decode_fl(source) } - fn decode_fl_into(&self, source: S, dst: &mut [f32]) -> std::io::Result<()> + fn decode_fl_into(&self, source: S, dst: &mut [f32]) -> io::Result<()> where S: Read, { (**self).decode_fl_into(source, dst) } - fn decode_fd(&self, source: S) -> std::io::Result + fn decode_fd(&self, source: S) -> io::Result where S: Read, { (**self).decode_fd(source) } - fn decode_fd_into(&self, source: S, dst: &mut [f64]) -> std::io::Result<()> + fn decode_fd_into(&self, source: S, dst: &mut [f64]) -> io::Result<()> where S: Read, { (**self).decode_fd_into(source, dst) } - fn decode_tag(&self, source: S) -> std::io::Result + fn decode_tag(&self, source: S) -> io::Result where S: Read, { @@ -380,119 +380,119 @@ where (**self).endianness() } - fn decode_us(&self, source: S) -> std::io::Result + fn decode_us(&self, source: S) -> io::Result where S: Read, { (**self).decode_us(source) } - fn decode_us_into(&self, source: S, dst: &mut [u16]) -> std::io::Result<()> + fn decode_us_into(&self, source: S, dst: &mut [u16]) -> io::Result<()> where S: Read, { (**self).decode_us_into(source, dst) } - fn decode_ul(&self, source: S) -> std::io::Result + fn decode_ul(&self, source: S) -> io::Result where S: Read, { (**self).decode_ul(source) } - fn decode_ul_into(&self, source: S, dst: &mut [u32]) -> std::io::Result<()> + fn decode_ul_into(&self, source: S, dst: &mut [u32]) -> io::Result<()> where S: Read, { (**self).decode_ul_into(source, dst) } - fn decode_uv(&self, source: S) -> std::io::Result + fn decode_uv(&self, source: S) -> io::Result where S: Read, { (**self).decode_uv(source) } - fn decode_uv_into(&self, source: S, dst: &mut [u64]) -> std::io::Result<()> + fn decode_uv_into(&self, source: S, dst: &mut [u64]) -> io::Result<()> where S: Read, { (**self).decode_uv_into(source, dst) } - fn decode_ss(&self, source: S) -> std::io::Result + fn decode_ss(&self, source: S) -> io::Result where S: Read, { (**self).decode_ss(source) } - fn decode_ss_into(&self, source: S, dst: &mut [i16]) -> std::io::Result<()> + fn decode_ss_into(&self, source: S, dst: &mut [i16]) -> io::Result<()> where S: Read, { (**self).decode_ss_into(source, dst) } - fn decode_sl(&self, source: S) -> std::io::Result + fn decode_sl(&self, source: S) -> io::Result where S: Read, { (**self).decode_sl(source) } - fn decode_sl_into(&self, source: S, dst: &mut [i32]) -> std::io::Result<()> + fn decode_sl_into(&self, source: S, dst: &mut [i32]) -> io::Result<()> where S: Read, { (**self).decode_sl_into(source, dst) } - fn decode_sv(&self, source: S) -> std::io::Result + fn decode_sv(&self, source: S) -> io::Result where S: Read, { (**self).decode_sv(source) } - fn decode_sv_into(&self, source: S, dst: &mut [i64]) -> std::io::Result<()> + fn decode_sv_into(&self, source: S, dst: &mut [i64]) -> io::Result<()> where S: Read, { (**self).decode_sv_into(source, dst) } - fn decode_fl(&self, source: S) -> std::io::Result + fn decode_fl(&self, source: S) -> io::Result where S: Read, { (**self).decode_fl(source) } - fn decode_fl_into(&self, source: S, dst: &mut [f32]) -> std::io::Result<()> + fn decode_fl_into(&self, source: S, dst: &mut [f32]) -> io::Result<()> where S: Read, { (**self).decode_fl_into(source, dst) } - fn decode_fd(&self, source: S) -> std::io::Result + fn decode_fd(&self, source: S) -> io::Result where S: Read, { (**self).decode_fd(source) } - fn decode_fd_into(&self, source: S, dst: &mut [f64]) -> std::io::Result<()> + fn decode_fd_into(&self, source: S, dst: &mut [f64]) -> io::Result<()> where S: Read, { (**self).decode_fd_into(source, dst) } - fn decode_tag(&self, source: S) -> std::io::Result + fn decode_tag(&self, source: S) -> io::Result where S: Read, { diff --git a/encoding/src/encode/explicit_be.rs b/encoding/src/encode/explicit_be.rs index d8f3b1fec..a85e2d974 100644 --- a/encoding/src/encode/explicit_be.rs +++ b/encoding/src/encode/explicit_be.rs @@ -1,15 +1,18 @@ //! Explicit VR Big Endian syntax transfer implementation. use crate::encode::basic::BigEndianBasicEncoder; -use crate::encode::*; +use crate::encode::{ + BasicEncode, Encode, Result, WriteHeaderSnafu, WriteItemDelimiterSnafu, WriteItemHeaderSnafu, + WriteOffsetTableSnafu, WriteSequenceDelimiterSnafu, WriteTagSnafu, +}; + use byteordered::byteorder::{BigEndian, ByteOrder}; use byteordered::Endianness; use dicom_core::header::{DataElementHeader, HasLength, Header}; use dicom_core::{PrimitiveValue, Tag, VR}; +use snafu::ResultExt; use std::io::{self, Write}; -type Result = std::result::Result; - /// A concrete encoder for the transfer syntax ExplicitVRBigEndian #[derive(Debug, Default, Clone)] pub struct ExplicitVRBigEndianEncoder { diff --git a/encoding/src/encode/explicit_le.rs b/encoding/src/encode/explicit_le.rs index 03f1a7081..dff50e12d 100644 --- a/encoding/src/encode/explicit_le.rs +++ b/encoding/src/encode/explicit_le.rs @@ -1,7 +1,10 @@ //! Explicit VR Little Endian syntax transfer implementation use crate::encode::basic::LittleEndianBasicEncoder; -use crate::encode::*; +use crate::encode::{ + BasicEncode, Encode, Result, WriteHeaderSnafu, WriteItemDelimiterSnafu, WriteItemHeaderSnafu, + WriteOffsetTableSnafu, WriteSequenceDelimiterSnafu, WriteTagSnafu, +}; use byteordered::byteorder::{ByteOrder, LittleEndian}; use byteordered::Endianness; use dicom_core::header::{DataElementHeader, HasLength, Header}; diff --git a/encoding/src/encode/implicit_le.rs b/encoding/src/encode/implicit_le.rs index 8b6a2b433..dd3fa9def 100644 --- a/encoding/src/encode/implicit_le.rs +++ b/encoding/src/encode/implicit_le.rs @@ -1,11 +1,15 @@ //! Implicit VR Big Endian syntax transfer implementation use crate::encode::basic::LittleEndianBasicEncoder; -use crate::encode::*; +use crate::encode::{ + BasicEncode, Encode, Result, WriteHeaderSnafu, WriteItemDelimiterSnafu, WriteItemHeaderSnafu, + WriteOffsetTableSnafu, WriteSequenceDelimiterSnafu, WriteTagSnafu, +}; use byteordered::byteorder::{ByteOrder, LittleEndian}; use byteordered::Endianness; use dicom_core::header::{DataElementHeader, HasLength, Header}; use dicom_core::{PrimitiveValue, Tag}; +use snafu::ResultExt; use std::io::{self, Write}; /// A concrete encoder for the transfer syntax ImplicitVRLittleEndian diff --git a/encoding/src/encode/mod.rs b/encoding/src/encode/mod.rs index f7a474c0a..9718b16b4 100644 --- a/encoding/src/encode/mod.rs +++ b/encoding/src/encode/mod.rs @@ -144,12 +144,12 @@ pub trait BasicEncode { #[inline] fn with_encoder(&self, f_le: F1, f_be: F2) -> T where - F1: FnOnce(self::basic::LittleEndianBasicEncoder) -> T, - F2: FnOnce(self::basic::BigEndianBasicEncoder) -> T, + F1: FnOnce(basic::LittleEndianBasicEncoder) -> T, + F2: FnOnce(basic::BigEndianBasicEncoder) -> T, { match self.endianness() { - Endianness::Little => f_le(self::basic::LittleEndianBasicEncoder), - Endianness::Big => f_be(self::basic::BigEndianBasicEncoder), + Endianness::Little => f_le(basic::LittleEndianBasicEncoder), + Endianness::Big => f_be(basic::BigEndianBasicEncoder), } } From 90a6c7b714d5a01e19d85a2cd8e7728059c93bb3 Mon Sep 17 00:00:00 2001 From: Eduardo Pinho Date: Tue, 19 Mar 2024 21:05:35 +0000 Subject: [PATCH 04/12] [parser] rearrange imports --- parser/src/dataset/read.rs | 1 - parser/src/dataset/write.rs | 4 ++-- parser/src/stateful/decode.rs | 1 - 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/parser/src/dataset/read.rs b/parser/src/dataset/read.rs index 8d856f7a6..19987a731 100644 --- a/parser/src/dataset/read.rs +++ b/parser/src/dataset/read.rs @@ -12,7 +12,6 @@ use dicom_encoding::transfer_syntax::TransferSyntax; use snafu::{Backtrace, ResultExt, Snafu}; use std::cmp::Ordering; use std::io::Read; -use std::iter::Iterator; use super::{DataToken, SeqTokenType}; diff --git a/parser/src/dataset/write.rs b/parser/src/dataset/write.rs index 45fa98762..bfa77faf8 100644 --- a/parser/src/dataset/write.rs +++ b/parser/src/dataset/write.rs @@ -6,9 +6,9 @@ //! to a writer. //! In this process, the writer will also adapt values //! to the necessary DICOM encoding rules. -use crate::dataset::*; +use crate::dataset::{DataToken, SeqTokenType}; use crate::stateful::encode::StatefulEncoder; -use dicom_core::{DataElementHeader, Length, VR}; +use dicom_core::{DataElementHeader, Length, Tag, VR}; use dicom_encoding::encode::EncodeTo; use dicom_encoding::text::SpecificCharacterSet; use dicom_encoding::transfer_syntax::DynEncoder; diff --git a/parser/src/stateful/decode.rs b/parser/src/stateful/decode.rs index 72d24bbac..b3b5a9ee9 100644 --- a/parser/src/stateful/decode.rs +++ b/parser/src/stateful/decode.rs @@ -18,7 +18,6 @@ use dicom_encoding::transfer_syntax::{DynDecoder, TransferSyntax}; use smallvec::smallvec; use snafu::{Backtrace, OptionExt, ResultExt, Snafu}; use std::io::Read; -use std::iter::Iterator; use std::{fmt::Debug, io::Seek, io::SeekFrom}; #[derive(Debug, Snafu)] From 5f9b8d432eca84ef0e4c8bf478b73b806afb94e3 Mon Sep 17 00:00:00 2001 From: Eduardo Pinho Date: Tue, 19 Mar 2024 21:05:46 +0000 Subject: [PATCH 05/12] [parser] remove unused constructs --- parser/src/util.rs | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/parser/src/util.rs b/parser/src/util.rs index 63e88d717..ab76e72b2 100644 --- a/parser/src/util.rs +++ b/parser/src/util.rs @@ -1,22 +1,4 @@ -use std::io; -use std::io::{Read, Seek, SeekFrom}; - -/** A private type trait for the ability to efficiently implement stream skipping. - */ -pub trait ForwardSeek { - fn skip(&mut self, n: u64) -> io::Result; -} - -impl ForwardSeek for S -where - S: Seek, -{ - fn skip(&mut self, n: u64) -> io::Result { - let curr_pos = self.stream_position()?; - let new_pos = self.seek(SeekFrom::Current(n as i64))?; - Ok(new_pos - curr_pos) - } -} +use std::io::{Read, Seek}; pub trait ReadSeek: Read + Seek {} impl ReadSeek for T where T: Read + Seek {} From 6931fdb1d0900a696b6242e9e7c13d61c96dc3c6 Mon Sep 17 00:00:00 2001 From: Eduardo Pinho Date: Tue, 19 Mar 2024 21:05:58 +0000 Subject: [PATCH 06/12] [object] remove unused module utils --- object/src/lib.rs | 2 -- object/src/util.rs | 23 ----------------------- 2 files changed, 25 deletions(-) delete mode 100644 object/src/util.rs diff --git a/object/src/lib.rs b/object/src/lib.rs index c4be065f0..22dd28917 100644 --- a/object/src/lib.rs +++ b/object/src/lib.rs @@ -139,8 +139,6 @@ pub mod meta; pub mod ops; pub mod tokens; -mod util; - pub use crate::file::{from_reader, open_file, OpenFileOptions}; pub use crate::mem::InMemDicomObject; pub use crate::meta::{FileMetaTable, FileMetaTableBuilder}; diff --git a/object/src/util.rs b/object/src/util.rs deleted file mode 100644 index cc3a5df65..000000000 --- a/object/src/util.rs +++ /dev/null @@ -1,23 +0,0 @@ -use std::io; -use std::io::{Read, Seek, SeekFrom}; - -/** A private type trait for the ability to efficiently implement stream skipping. - */ -pub trait ForwardSeek { - fn skip(&mut self, n: u64) -> io::Result; -} - -impl ForwardSeek for S -where - S: Seek, -{ - fn skip(&mut self, n: u64) -> io::Result { - let curr_pos = self.stream_position()?; - let new_pos = self.seek(SeekFrom::Current(n as i64))?; - Ok(new_pos - curr_pos) - } -} - -/// A trait that combines for `Read` and `Seek`. -pub trait ReadSeek: Read + Seek {} -impl ReadSeek for T where T: Read + Seek {} From 4e175ed9cd2bd790b3df247dd9cedee62080badf Mon Sep 17 00:00:00 2001 From: Eduardo Pinho Date: Tue, 19 Mar 2024 21:06:16 +0000 Subject: [PATCH 07/12] [ts-registry] re-qualify io::copy call --- transfer-syntax-registry/src/adapters/rle_lossless.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/transfer-syntax-registry/src/adapters/rle_lossless.rs b/transfer-syntax-registry/src/adapters/rle_lossless.rs index cf89c8922..e3f06a7ce 100644 --- a/transfer-syntax-registry/src/adapters/rle_lossless.rs +++ b/transfer-syntax-registry/src/adapters/rle_lossless.rs @@ -252,7 +252,7 @@ impl PackBitsReader { bytes_read += 1; } else if h >= 0 { let num_vals = h as usize + 1; - std::io::copy(&mut reader.by_ref().take(num_vals as u64), &mut buffer)?; + io::copy(&mut reader.by_ref().take(num_vals as u64), &mut buffer)?; bytes_read += num_vals; } else { // h = -128 is a no-op. From e4006a8fe9eac2977fb386cef73a3ab7d13f5273 Mon Sep 17 00:00:00 2001 From: Eduardo Pinho Date: Tue, 19 Mar 2024 21:06:46 +0000 Subject: [PATCH 08/12] [pixeldata] remove unused error variants in transcode error --- pixeldata/src/transcode.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/pixeldata/src/transcode.rs b/pixeldata/src/transcode.rs index 0295dd72f..94f723a3f 100644 --- a/pixeldata/src/transcode.rs +++ b/pixeldata/src/transcode.rs @@ -36,9 +36,6 @@ pub(crate) enum InnerError { /// Could not decode pixel data of receiving object DecodePixelData { source: crate::Error }, - /// Could not read receiving object - ReadObject { source: dicom_object::ReadError }, - /// Could not encode pixel data to target encoding EncodePixelData { source: dicom_encoding::adapters::EncodeError, @@ -46,9 +43,6 @@ pub(crate) enum InnerError { /// Unsupported bits per sample ({bits_allocated}) UnsupportedBitsAllocated { bits_allocated: u16 }, - - /// Encoding multi-frame objects is not implemented - MultiFrameEncodingNotImplemented, } /// Alias for the result of transcoding a DICOM object. From 9b2eff34583ffc7887ba56ba11e808e2c22c0aa3 Mon Sep 17 00:00:00 2001 From: Eduardo Pinho Date: Wed, 20 Mar 2024 08:33:21 +0000 Subject: [PATCH 09/12] [core] Reorganize imports in test modules --- core/src/header.rs | 6 +----- core/src/lib.rs | 1 - core/src/value/deserialize.rs | 1 - core/src/value/mod.rs | 1 - core/src/value/partial.rs | 4 +--- 5 files changed, 2 insertions(+), 11 deletions(-) diff --git a/core/src/header.rs b/core/src/header.rs index d30252dfe..1d43c09bb 100644 --- a/core/src/header.rs +++ b/core/src/header.rs @@ -1357,11 +1357,7 @@ impl fmt::Display for Length { #[cfg(test)] mod tests { use super::*; - use crate::{ - dicom_value, - value::{InMemFragment, PixelFragmentSequence}, - DicomValue, - }; + use crate::{dicom_value, value::PixelFragmentSequence, DicomValue}; #[test] fn to_clean_string() { diff --git a/core/src/lib.rs b/core/src/lib.rs index f8fd8cf72..56b4cb3e5 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -145,7 +145,6 @@ macro_rules! dicom_value { #[cfg(test)] mod tests { - use crate::dicom_value; use crate::value::PrimitiveValue; use smallvec::smallvec; diff --git a/core/src/value/deserialize.rs b/core/src/value/deserialize.rs index 38ceb40af..d32f8beab 100644 --- a/core/src/value/deserialize.rs +++ b/core/src/value/deserialize.rs @@ -460,7 +460,6 @@ pub fn parse_datetime_partial(buf: &[u8]) -> Result { #[cfg(test)] mod tests { use super::*; - use chrono::{FixedOffset, NaiveDate, NaiveTime}; #[test] fn test_parse_date() { diff --git a/core/src/value/mod.rs b/core/src/value/mod.rs index 8423b4dc2..8aa21ae1f 100644 --- a/core/src/value/mod.rs +++ b/core/src/value/mod.rs @@ -1086,7 +1086,6 @@ impl

DicomValueType for PixelFragmentSequence

{ mod tests { use super::*; use crate::dicom_value; - use crate::header::EmptyObject; use smallvec::smallvec; #[test] diff --git a/core/src/value/partial.rs b/core/src/value/partial.rs index 209980f4b..53c22720b 100644 --- a/core/src/value/partial.rs +++ b/core/src/value/partial.rs @@ -987,10 +987,8 @@ impl PartialOrd for PreciseDateTime { #[cfg(test)] mod tests { - use crate::value::range::AsRange; - use super::*; - use chrono::{NaiveDateTime, TimeZone}; + use chrono::TimeZone; #[test] fn test_dicom_date() { From 9dd1bd463e4105320a334c74f20e3ee3e16fc745 Mon Sep 17 00:00:00 2001 From: Eduardo Pinho Date: Wed, 20 Mar 2024 08:33:41 +0000 Subject: [PATCH 10/12] [json] Reorganize imports in test modules --- json/src/ser/mod.rs | 4 ++-- json/src/ser/value.rs | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/json/src/ser/mod.rs b/json/src/ser/mod.rs index f9a9fd1e4..f8a1d552b 100644 --- a/json/src/ser/mod.rs +++ b/json/src/ser/mod.rs @@ -304,8 +304,8 @@ mod tests { use pretty_assertions::assert_eq; use dicom_core::value::DataSetSequence; - use dicom_core::{dicom_value, value::DicomDate, Tag}; - use dicom_core::{Length, VR}; + use dicom_core::Length; + use dicom_core::{dicom_value, value::DicomDate}; use dicom_dictionary_std::tags; use serde_json::json; diff --git a/json/src/ser/value.rs b/json/src/ser/value.rs index e06ec8d5c..5da391190 100644 --- a/json/src/ser/value.rs +++ b/json/src/ser/value.rs @@ -194,7 +194,6 @@ impl<'a> From<&'a str> for PersonNameDef<'a> { mod tests { use dicom_core::dicom_value; use dicom_core::value::DicomDate; - use dicom_core::PrimitiveValue; use pretty_assertions::assert_eq; use serde_json::json; use serde_json::Value; From d72053e491753ade724a35d8f6b751db74a8aa22 Mon Sep 17 00:00:00 2001 From: Eduardo Pinho Date: Wed, 20 Mar 2024 08:33:57 +0000 Subject: [PATCH 11/12] [object] Reorganize imports in test modules and evade rust-analyzer bug --- object/src/mem.rs | 14 +++++--------- object/tests/integration_test.rs | 2 -- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/object/src/mem.rs b/object/src/mem.rs index fc32f6404..4db47d570 100644 --- a/object/src/mem.rs +++ b/object/src/mem.rs @@ -872,7 +872,7 @@ where &self, selector: impl Into, ) -> Result<&Value, InMemFragment>, AtAccessError> { - let selector = selector.into(); + let selector: AttributeSelector = selector.into(); let mut obj = self; for (i, step) in selector.iter().enumerate() { @@ -1719,23 +1719,19 @@ fn even_len(l: u32) -> u32 { mod tests { use super::*; - use crate::AtAccessError; - use crate::{meta::FileMetaTableBuilder, open_file}; + use crate::open_file; use byteordered::Endianness; use dicom_core::chrono::FixedOffset; - use dicom_core::ops::AttributeSelector; - use dicom_core::value::{DicomDate, DicomDateTime, DicomTime, PrimitiveValue}; + use dicom_core::value::{DicomDate, DicomDateTime, DicomTime}; use dicom_core::{ dicom_value, - header::{DataElementHeader, Length, VR}, - ops::{AttributeAction, AttributeOp}, + header::DataElementHeader, }; use dicom_encoding::{ decode::{basic::BasicDecoder, implicit_le::ImplicitVRLittleEndianDecoder}, encode::{implicit_le::ImplicitVRLittleEndianEncoder, EncoderFor}, }; - use dicom_parser::{dataset::IntoTokens, StatefulDecoder}; - use tempfile; + use dicom_parser::StatefulDecoder; fn assert_obj_eq(obj1: &InMemDicomObject, obj2: &InMemDicomObject) where diff --git a/object/tests/integration_test.rs b/object/tests/integration_test.rs index 658889efd..86b599e72 100644 --- a/object/tests/integration_test.rs +++ b/object/tests/integration_test.rs @@ -11,8 +11,6 @@ use dicom_object::{ mem::InMemDicomObject, open_file, }; -use dicom_test_files; - #[test] fn test_ob_value_with_unknown_length() { let path = From d3a59073deeadc89bf21fef494ff4eb755ace420 Mon Sep 17 00:00:00 2001 From: Eduardo Pinho Date: Wed, 20 Mar 2024 08:34:19 +0000 Subject: [PATCH 12/12] [pixeldata] Reorganize imports in test modules --- pixeldata/src/gdcm.rs | 1 - pixeldata/src/lib.rs | 1 - pixeldata/src/transcode.rs | 1 - 3 files changed, 3 deletions(-) diff --git a/pixeldata/src/gdcm.rs b/pixeldata/src/gdcm.rs index f96c1a56f..d70e6d5e1 100644 --- a/pixeldata/src/gdcm.rs +++ b/pixeldata/src/gdcm.rs @@ -2,7 +2,6 @@ use crate::*; use dicom_dictionary_std::tags; -use dicom_encoding::adapters::DecodeError; use dicom_encoding::transfer_syntax::TransferSyntaxIndex; use dicom_transfer_syntax_registry::TransferSyntaxRegistry; use gdcm_rs::{ diff --git a/pixeldata/src/lib.rs b/pixeldata/src/lib.rs index 5fe82017f..860cfb3b9 100644 --- a/pixeldata/src/lib.rs +++ b/pixeldata/src/lib.rs @@ -1981,7 +1981,6 @@ where mod tests { use super::*; use dicom_object::open_file; - use dicom_test_files; fn is_send_and_sync() where diff --git a/pixeldata/src/transcode.rs b/pixeldata/src/transcode.rs index 94f723a3f..7e64c10d4 100644 --- a/pixeldata/src/transcode.rs +++ b/pixeldata/src/transcode.rs @@ -269,7 +269,6 @@ mod tests { use super::*; use dicom_dictionary_std::uids; use dicom_object::open_file; - use dicom_test_files; use dicom_transfer_syntax_registry::entries::{JPEG_EXTENDED, ENCAPSULATED_UNCOMPRESSED_EXPLICIT_VR_LITTLE_ENDIAN}; #[cfg(feature = "native")] use dicom_transfer_syntax_registry::entries::JPEG_BASELINE;