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

Add number formatting #15

Merged
merged 2 commits into from Dec 13, 2017
Merged

Add number formatting #15

merged 2 commits into from Dec 13, 2017

Conversation

ghost
Copy link

@ghost ghost commented Dec 13, 2017

As discussed in #13.

I ended up splitting it into two macros, one for integers and one for floats. I also spilt the tests into three macros for unsigned and signed integers, and floats.

Let me know if you have any comments 👍

'x' | 'X' => self.write_str("0x").unwrap(),
_ => {
let mut msg = String::new();
write!(msg, "alternate ('#') cannot be used with type {:?}", ty).unwrap();
Copy link
Owner

Choose a reason for hiding this comment

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

when I first wrote this lib I didn't know about format!(). Please use that instead here. You can even get rid of msg variable alltogether.

Copy link
Owner

Choose a reason for hiding this comment

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

whoops, I'll handle it in a separate commit... maybe (who really cares, haha).

Thanks for the PR!


pub use types::{Result, FmtError, Alignment, Sign};
pub use fmtstr::strfmt_map;
pub use formatter::Formatter;

// u128 & i128 unstable (see https://github.com/rust-lang/rust/issues/35118)
fmtint!(u8 i8 u16 i16 u32 i32 u64 i64 usize isize);
Copy link
Owner

Choose a reason for hiding this comment

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

whoa! I didn't know this was possible, I thought they would have to each be their own line. Good work!

@vitiral
Copy link
Owner

vitiral commented Dec 13, 2017

Looks good, from travis run:

test tests::strfmt::test_i8 ... ok
test tests::strfmt::test_i16 ... ok
test tests::strfmt::test_i32 ... ok
test tests::strfmt::test_i64 ... ok
test tests::strfmt::test_isize ... ok
test tests::strfmt::test_u8 ... ok
test tests::strfmt::test_u16 ... ok
test tests::strfmt::test_u32 ... ok
test tests::strfmt::test_u64 ... ok
test tests::strfmt::test_usize ... ok
test tests::strfmt::test_f32 ... ok
test tests::strfmt::test_f64 ... ok
test tests::strfmt::test_ints_basic ... ok

@vitiral vitiral merged commit 48ee0c5 into vitiral:master Dec 13, 2017
@ghost
Copy link
Author

ghost commented Dec 13, 2017

No problem 👍

@vitiral
Copy link
Owner

vitiral commented Jan 4, 2018

I just publised v0.1.6 with these changes, thanks!

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.

1 participant