-
Notifications
You must be signed in to change notification settings - Fork 178
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
Implement SignedFixedDecimal
and UnsignedFixedDecimal
#5667
base: main
Are you sure you want to change the base?
Conversation
Good start; try to stick with the names we discussed in the thread. |
…nd truncation methods public
… in FormattedDuration
…in HeterogenousToFormatter
…tter in JS tiny loader
…remove redundant sections
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work
{ | ||
let mut num = SignedFixedDecimal::from(related_iso); | ||
num.pad_start(l.to_len() as i16); | ||
num | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issue: Why did you change padded_start
to pad_start
?
However, you'll need the { ... }
block anyway if SignedFixedDecimal doesn't duplicate the functions of the inner type. Maybe we can just duplicate the -ed
functions.
We discussed the -ed
functions in June: #2902 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because padded_start
returns UnsignedFixedDecimal
, however, pad_start
changes the UnsignedFixedDecimal
inside the UnsignedFixedDecimal
.
@@ -5,7 +5,7 @@ version = 3 | |||
[[package]] | |||
name = "diplomat" | |||
version = "0.8.0" | |||
source = "git+https://github.com/rust-diplomat/diplomat?rev=8744ac97162341f347b63131969ad736e1047f6d#8744ac97162341f347b63131969ad736e1047f6d" | |||
source = "git+https://github.com/rust-diplomat/diplomat?rev=b49d63ec2a50a456b4b6e9d072d3650dca153ff8#b49d63ec2a50a456b4b6e9d072d3650dca153ff8" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Try not to include Cargo.lock changes in PRs with other functional changes. This Cargo.lock file might be stale, but it should be fixed in a standalone PR.
tutorials/c/Cargo.lock
Outdated
@@ -47,7 +47,7 @@ dependencies = [ | |||
[[package]] | |||
name = "diplomat" | |||
version = "0.8.0" | |||
source = "git+https://github.com/rust-diplomat/diplomat?rev=fe5201dd04ee6614942f817b291e90cb01440c19#fe5201dd04ee6614942f817b291e90cb01440c19" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Avoid lockfile diffs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
@@ -19,13 +19,13 @@ use crate::ParseError; | |||
/// nor a sign in the exponent, and behaves differently in pluralization. | |||
#[derive(Debug, Clone, PartialEq)] | |||
pub struct CompactDecimal { | |||
significand: FixedDecimal, | |||
significand: SignedFixedDecimal, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should eventually make Compact
composable, so that you can have an UnsignedCompactDecimal
, for example. We can do that later in a different PR.
@@ -3167,10 +2527,6 @@ fn test_from_str_scientific() { | |||
pub output: &'static str, | |||
} | |||
let cases = [ | |||
TestCase { | |||
input_str: "-5.4e10", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: Add back some of these cases as failure cases to demonstrate that UnsignedFixedDecimal will fail to parse strings with a minus sign
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, and for the ones starting with +
too.
// Check if the output string starts with a plus sign and remove it, | ||
// because we do not show sign for unsigned fixed decimal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: maybe just reject strings with a +
sign in UnsignedRoundingMode. It's okay to be more strict.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I agree with you.
As Rust behavior with unsigned types is as follows:
fn main() {
let x: u32;
x = +20;
println!("x is: {}", x);
}
This results in the following error:
error: leading `+` is not supported
--> src/main.rs:3:9
|
3 | x = +20;
| ^ unexpected `+`
|
help: try removing the `+`
|
3 - x = +20;
3 + x = 20;
|
…al to the documentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM; please sync to the latest main branch
Related Issues: #5065