Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change examples to use Display instead of Debug. #198

Merged
merged 1 commit into from
Aug 3, 2020

Conversation

iliekturtles
Copy link
Owner

mks and si examples are updated to use format_args or
into_format_args as appropriate so that the Display trait can be
used to display quantities in specific units. Part of #123.

@adamreichold
Copy link
Contributor

Rustfmt does seem to have a nit to add:

diff --git a/examples/mks.rs b/examples/mks.rs
index 76aa92e..568d542 100644
--- a/examples/mks.rs
+++ b/examples/mks.rs
@@ -3,14 +3,17 @@
 #[macro_use]
 extern crate uom;
 
-use uom::fmt::DisplayStyle::*;
 use length::{foot, meter};
+use uom::fmt::DisplayStyle::*;
 
 fn main() {
     let l1 = f32::Length::new::<meter>(100.0);
 
-    println!("{} = {}",
-        l1.into_format_args(meter, Abbreviation), l1.into_format_args(foot, Abbreviation));
+    println!(
+        "{} = {}",
+        l1.into_format_args(meter, Abbreviation),
+        l1.into_format_args(foot, Abbreviation)
+    );
 }
 
 #[macro_use]
diff --git a/examples/si.rs b/examples/si.rs
index 0cab985..fd1deb8 100644
--- a/examples/si.rs
+++ b/examples/si.rs
@@ -22,20 +22,23 @@ fn main() {
     let s = Time::format_args(second, Abbreviation);
 
     // Print results of simple formulas using different output units.
-    println!("{} + {} = {}",
+    println!("{} + {} = {}", m.with(l1), cm.with(l2), m.with(l1 + l2));
+    println!(
+        "{} + {} = {}",
         m.with(l1),
         cm.with(l2),
-        m.with(l1 + l2));
-    println!("{} + {} = {}",
-        m.with(l1),
-        cm.with(l2),
-        (l1 + l2).into_format_args(kilometer, Abbreviation));
-    println!("{} / {} = {}",
+        (l1 + l2).into_format_args(kilometer, Abbreviation)
+    );
+    println!(
+        "{} / {} = {}",
         m.with(l1),
         s.with(t1),
-        v1.into_format_args(meter_per_second, Abbreviation));
-    println!("{} / {} = {}",
+        v1.into_format_args(meter_per_second, Abbreviation)
+    );
+    println!(
+        "{} / {} = {}",
         m.with(l1),
         s.with(t1),
-        v1.into_format_args(kilometer_per_second, Abbreviation));
+        v1.into_format_args(kilometer_per_second, Abbreviation)
+    );
 }

examples/mks.rs Outdated
@@ -3,18 +3,14 @@
#[macro_use]
extern crate uom;

use uom::fmt::DisplayStyle::*;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I am not overly fond of glob imports and would suggest avoiding them in examples for pedagogical reasons.

mks and si examples are updated to use `format_args` or
`into_format_args` as appropriate so that the `Display` trait can be
used to display quantities in specific units. Part of #123.
@iliekturtles iliekturtles force-pushed the use-display-in-examples branch from a796151 to 23287ba Compare August 2, 2020 13:06
@iliekturtles
Copy link
Owner Author

Formatting fixes finally pushed. Had a corrupt rustup that took a bit to fix.

@adamreichold
Copy link
Contributor

LGTM

@iliekturtles iliekturtles merged commit ae82174 into master Aug 3, 2020
@iliekturtles iliekturtles deleted the use-display-in-examples branch August 3, 2020 11:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants