Skip to content

Commit

Permalink
rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Enet4 committed May 18, 2020
1 parent 7586321 commit cfad623
Show file tree
Hide file tree
Showing 12 changed files with 134 additions and 99 deletions.
9 changes: 4 additions & 5 deletions core/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ use std::str::{from_utf8, FromStr};
pub trait HasLength {
/// Retrieve the value data's length as specified by the data element or
/// item, in bytes.
///
///
/// It is named `length` to make it distinct from the conventional method
/// signature `len(&self) -> usize` for the number of elements of a
/// collection.
///
///
/// According to the standard, the concrete value size may be undefined,
/// which can be the case for sequence elements or specific primitive
/// values.
Expand Down Expand Up @@ -47,7 +47,7 @@ pub trait Header: HasLength {
}

/// Stub type representing a non-existing DICOM object.
///
///
/// This type implements `HasLength`, but cannot be instantiated.
/// This makes it so that `Value<EmptyObject>` is sure to be either a primitive
/// value or a sequence with no items.
Expand Down Expand Up @@ -141,7 +141,6 @@ impl<'a, I> Header for &'a DataElement<I> {
fn tag(&self) -> Tag {
(**self).tag()
}

}

impl<'v, I> HasLength for DataElementRef<'v, I> {
Expand Down Expand Up @@ -200,7 +199,7 @@ where
I: HasLength,
{
/// Create a primitive data element from the given parts.
///
///
/// This method will not check whether the value representation is
/// compatible with the given value.
pub fn new(tag: Tag, vr: VR, value: Value<I>) -> Self {
Expand Down
24 changes: 12 additions & 12 deletions encoding/src/encode/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,43 +369,43 @@ where
{
fn encode_tag(&self, to: &mut W, tag: Tag) -> Result<()>
where
W: Write
W: Write,
{
(**self).encode_tag(to, tag)
}

fn encode_element_header(&self, to: &mut W, de: DataElementHeader) -> Result<usize>
where
W: Write
W: Write,
{
(**self).encode_element_header(to, de)
}

fn encode_item_header(&self, to: &mut W, len: u32) -> Result<()>
where
W: Write
W: Write,
{
(**self).encode_item_header(to, len)
}

fn encode_item_delimiter(&self, to: &mut W) -> Result<()>
where
W: Write
W: Write,
{
(**self).encode_item_delimiter(to)
}

fn encode_sequence_delimiter(&self, to: &mut W) -> Result<()>
where
W: Write
W: Write,
{
(**self).encode_sequence_delimiter(to)
}

/// Encode and write a primitive DICOM value to the given destination.
fn encode_primitive(&self, to: &mut W, value: &PrimitiveValue) -> Result<usize>
where
W: Write
W: Write,
{
(**self).encode_primitive(to, value)
}
Expand All @@ -417,43 +417,43 @@ where
{
fn encode_tag(&self, to: &mut W, tag: Tag) -> Result<()>
where
W: Write
W: Write,
{
(**self).encode_tag(to, tag)
}

fn encode_element_header(&self, to: &mut W, de: DataElementHeader) -> Result<usize>
where
W: Write
W: Write,
{
(**self).encode_element_header(to, de)
}

fn encode_item_header(&self, to: &mut W, len: u32) -> Result<()>
where
W: Write
W: Write,
{
(**self).encode_item_header(to, len)
}

fn encode_item_delimiter(&self, to: &mut W) -> Result<()>
where
W: Write
W: Write,
{
(**self).encode_item_delimiter(to)
}

fn encode_sequence_delimiter(&self, to: &mut W) -> Result<()>
where
W: Write
W: Write,
{
(**self).encode_sequence_delimiter(to)
}

/// Encode and write a primitive DICOM value to the given destination.
fn encode_primitive(&self, to: &mut W, value: &PrimitiveValue) -> Result<usize>
where
W: Write
W: Write,
{
(**self).encode_primitive(to, value)
}
Expand Down
2 changes: 1 addition & 1 deletion encoding/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ where
}

/// Type alias for a type erased text codec.
///
///
/// It is important because stateful decoders may need to change the expected
/// text encoding format at run-time.
pub type DynamicTextCodec = Box<dyn TextCodec>;
Expand Down
4 changes: 3 additions & 1 deletion encoding/src/transfer_syntax/implicit_le.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,9 @@ mod tests {
// don't read any data, just skip
// cursor should be @ #34 after skipping
assert_eq!(
cursor.seek(SeekFrom::Current(elem.length().0 as i64)).unwrap(),
cursor
.seek(SeekFrom::Current(elem.length().0 as i64))
.unwrap(),
34
);
}
Expand Down
21 changes: 9 additions & 12 deletions encoding/src/transfer_syntax/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,18 +323,15 @@ impl<A> TransferSyntax<A> {
W: ?Sized + Write,
{
match (self.byte_order, self.explicit_vr) {
(Endianness::Little, false) => Some(Box::new(
EncoderFor::new(
implicit_le::ImplicitVRLittleEndianEncoder::default())),
),
(Endianness::Little, true) => Some(Box::new(
EncoderFor::new(
explicit_le::ExplicitVRLittleEndianEncoder::default())),
),
(Endianness::Big, true) => Some(Box::new(
EncoderFor::new(
explicit_be::ExplicitVRBigEndianEncoder::default())),
),
(Endianness::Little, false) => Some(Box::new(EncoderFor::new(
implicit_le::ImplicitVRLittleEndianEncoder::default(),
))),
(Endianness::Little, true) => Some(Box::new(EncoderFor::new(
explicit_le::ExplicitVRLittleEndianEncoder::default(),
))),
(Endianness::Big, true) => Some(Box::new(EncoderFor::new(
explicit_be::ExplicitVRBigEndianEncoder::default(),
))),
_ => None,
}
}
Expand Down
21 changes: 11 additions & 10 deletions object/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ pub use dicom_parser::error::{Error, Result};
/// The default implementation of a root DICOM object.
pub type DefaultDicomObject = RootDicomObject<mem::InMemDicomObject<StandardDataDictionary>>;

use std::fs::File;
use std::io::{BufWriter, Write};
use std::path::Path;
use dicom_core::header::Header;
use dicom_encoding::{transfer_syntax::TransferSyntaxIndex, text::SpecificCharacterSet};
use dicom_encoding::{text::SpecificCharacterSet, transfer_syntax::TransferSyntaxIndex};
use dicom_parser::dataset::{DataSetWriter, IntoTokens};
use dicom_transfer_syntax_registry::TransferSyntaxRegistry;
use std::fs::File;
use std::io::{BufWriter, Write};
use std::path::Path;

/// Trait type for a DICOM object.
/// This is a high-level abstraction where an object is accessed and
Expand Down Expand Up @@ -118,7 +118,7 @@ where

// write meta group
self.meta.write(&mut to)?;

// prepare encoder
let registry = TransferSyntaxRegistry::default();
let ts = registry
Expand Down Expand Up @@ -197,23 +197,24 @@ where

#[cfg(test)]
mod tests {
use crate::RootDicomObject;
use crate::meta::FileMetaTableBuilder;
use crate::RootDicomObject;

#[test]
fn smoke_test() {
const FILE_NAME: &str = ".smoke-test.dcm";

let meta = FileMetaTableBuilder::new()
.transfer_syntax(dicom_transfer_syntax_registry::entries::EXPLICIT_VR_LITTLE_ENDIAN.uid())
.transfer_syntax(
dicom_transfer_syntax_registry::entries::EXPLICIT_VR_LITTLE_ENDIAN.uid(),
)
.media_storage_sop_class_uid("1.2.840.10008.5.1.4.1.1.1")
.media_storage_sop_instance_uid("1.2.3.456")
.implementation_class_uid("1.2.345.6.7890.1.234")
.build()
.unwrap();
let obj = RootDicomObject::new_empty_with_meta(
meta);

let obj = RootDicomObject::new_empty_with_meta(meta);

obj.write_to_file(FILE_NAME).unwrap();

let obj2 = RootDicomObject::open_file(FILE_NAME).unwrap();
Expand Down
Loading

0 comments on commit cfad623

Please sign in to comment.