From ba68f5e11e9a19cc1f5cf7bfa8f7060f9822f715 Mon Sep 17 00:00:00 2001 From: Rico Riedel Date: Mon, 1 Aug 2022 15:58:07 +0200 Subject: [PATCH] Reworked imports --- src/convert/mod.rs | 15 ++++++++------- src/main.rs | 17 +++++++++++++---- src/pattern/circle.rs | 4 ++-- src/pattern/line.rs | 4 ++-- src/pattern/mod.rs | 15 ++++++++++----- src/pattern/rhombus.rs | 6 +++--- src/pattern/wheel.rs | 4 ++-- src/printer.rs | 6 +++--- src/renderer.rs | 13 ++++++------- src/term.rs | 2 +- src/timer.rs | 6 +++--- src/vec.rs | 20 +------------------- 12 files changed, 54 insertions(+), 58 deletions(-) diff --git a/src/convert/mod.rs b/src/convert/mod.rs index cac3826..a6fed3c 100644 --- a/src/convert/mod.rs +++ b/src/convert/mod.rs @@ -1,9 +1,10 @@ -use crate::convert::char::{CharConverter, CharSample}; -use crate::convert::color::ColorConverter; -use crossterm::style::Color; +mod char; +mod color; -pub mod char; -pub mod color; +pub use crate::convert::char::*; +pub use crate::convert::color::*; + +use crossterm::style::Color; #[cfg_attr(test, mockall::automock)] pub trait Converter { @@ -30,8 +31,8 @@ impl Converter for ConverterImpl #[cfg(test)] mod test { use super::*; - use crate::convert::char::MockCharConverter; - use crate::convert::color::MockColorConverter; + use crate::convert::MockCharConverter; + use crate::convert::MockColorConverter; use mockall::predicate::*; #[test] diff --git a/src/main.rs b/src/main.rs index 71a7f4d..c2c25e8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,11 +1,20 @@ pub mod convert; -pub mod error; pub mod pattern; -pub mod printer; + +mod error; +mod printer; mod renderer; -pub mod term; +mod term; +mod timer; mod vec; -fn main() -> Result<(), error::Error> { +pub use error::*; +pub use printer::*; +pub use renderer::*; +pub use term::*; +pub use timer::*; +pub use vec::*; + +fn main() -> Result<(), Error> { Ok(()) } diff --git a/src/pattern/circle.rs b/src/pattern/circle.rs index 9c250c5..c6b2a89 100644 --- a/src/pattern/circle.rs +++ b/src/pattern/circle.rs @@ -1,5 +1,5 @@ -use crate::pattern::{Config, Pattern, PatternFactory}; -use crate::vec::Vector; +use crate::pattern::*; +use crate::Vector; #[derive(Default)] pub struct CircleFactory; diff --git a/src/pattern/line.rs b/src/pattern/line.rs index 5254625..281df04 100644 --- a/src/pattern/line.rs +++ b/src/pattern/line.rs @@ -1,5 +1,5 @@ -use crate::pattern::{Config, Pattern, PatternFactory}; -use crate::vec::Vector; +use crate::pattern::*; +use crate::Vector; #[derive(Default)] pub struct LineFactory; diff --git a/src/pattern/mod.rs b/src/pattern/mod.rs index a4ffa78..350aeae 100644 --- a/src/pattern/mod.rs +++ b/src/pattern/mod.rs @@ -1,9 +1,14 @@ -pub mod circle; -pub mod line; -pub mod rhombus; -pub mod wheel; +mod circle; +mod line; +mod rhombus; +mod wheel; -use crate::vec::Vector; +pub use circle::*; +pub use line::*; +pub use rhombus::*; +pub use wheel::*; + +use crate::Vector; #[derive(Copy, Clone, PartialEq, Debug)] pub struct Config { diff --git a/src/pattern/rhombus.rs b/src/pattern/rhombus.rs index c176ffd..69249e6 100644 --- a/src/pattern/rhombus.rs +++ b/src/pattern/rhombus.rs @@ -1,5 +1,5 @@ -use crate::pattern::{Config, Pattern, PatternFactory}; -use crate::vec::Vector; +use crate::pattern::*; +use crate::Vector; #[derive(Default)] pub struct RhombusFactory; @@ -42,7 +42,7 @@ mod test { fn name() { assert_eq!("rhombus", RhombusFactory::default().name()); } - + #[test] fn sample() { let config = Config { diff --git a/src/pattern/wheel.rs b/src/pattern/wheel.rs index a4463f5..cd40fc7 100644 --- a/src/pattern/wheel.rs +++ b/src/pattern/wheel.rs @@ -1,5 +1,5 @@ -use crate::pattern::{Config, Pattern, PatternFactory}; -use crate::vec::Vector; +use crate::pattern::*; +use crate::Vector; use std::f32::consts::PI; #[derive(Default)] diff --git a/src/printer.rs b/src/printer.rs index 440cbb1..4c621ef 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -1,5 +1,5 @@ -use crate::error::Error; -use crate::term::Terminal; +use crate::Error; +use crate::Terminal; use crossterm::cursor::*; use crossterm::style::*; use crossterm::terminal::*; @@ -96,7 +96,7 @@ impl Printer for PrinterImpl { #[cfg(test)] mod test { use super::*; - use crate::term::MockTerminal; + use crate::MockTerminal; use mockall::predicate::eq; #[test] diff --git a/src/renderer.rs b/src/renderer.rs index 6b8d6d6..fde039c 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -1,9 +1,8 @@ -use crate::convert::char::CharSample; -use crate::convert::Converter; -use crate::error::Error; -use crate::pattern::{Config, Sampler, SamplerFactory}; -use crate::printer::Printer; -use crate::vec::Vector; +use crate::convert::{CharSample, Converter}; +use crate::pattern::*; +use crate::Error; +use crate::Printer; +use crate::Vector; #[cfg_attr(test, mockall::automock)] pub trait Renderer { @@ -69,7 +68,7 @@ mod test { use crate::convert::MockConverter; use crate::pattern::MockSampler; use crate::pattern::MockSamplerFactory; - use crate::printer::MockPrinter; + use crate::MockPrinter; use crossterm::style::Color; use mockall::predicate::eq; use mockall::Sequence; diff --git a/src/term.rs b/src/term.rs index 3c6c388..eddc9a5 100644 --- a/src/term.rs +++ b/src/term.rs @@ -1,4 +1,4 @@ -use crate::error::Error; +use crate::Error; use crossterm::{Command, QueueableCommand}; use std::io::Write; diff --git a/src/timer.rs b/src/timer.rs index 27a17a0..67d2932 100644 --- a/src/timer.rs +++ b/src/timer.rs @@ -1,5 +1,5 @@ -use crate::error::Error; -use crate::renderer::Renderer; +use crate::Error; +use crate::Renderer; use std::thread; use std::time::{Duration, Instant}; @@ -58,7 +58,7 @@ impl Timer { #[cfg(test)] mod test { use super::*; - use crate::renderer::MockRenderer; + use crate::MockRenderer; use mockall::predicate::eq; use mockall::Sequence; diff --git a/src/vec.rs b/src/vec.rs index 2a789e4..60104bf 100644 --- a/src/vec.rs +++ b/src/vec.rs @@ -1,6 +1,4 @@ -use std::ops::Sub; - -#[derive(Copy, Clone, PartialEq, Debug, Default)] +#[derive(Copy, Clone, PartialEq, Debug, Default, derive_more::Sub)] pub struct Vector { pub x: f32, pub y: f32, @@ -36,14 +34,6 @@ impl Vector { } } -impl Sub for Vector { - type Output = Vector; - - fn sub(self, rhs: Self) -> Self::Output { - Self::new(self.x - rhs.x, self.y - rhs.y) - } -} - #[cfg(test)] mod test { use super::*; @@ -80,12 +70,4 @@ mod test { fn angle() { assert_abs_diff_eq!(-1.5, Vector::new(2.0, -20.0).angle(), epsilon = 0.1); } - - #[test] - fn sub() { - assert_eq!( - Vector::new(-5.0, 10.0), - Vector::new(3.0, 16.0) - Vector::new(8.0, 6.0) - ); - } }