-
Notifications
You must be signed in to change notification settings - Fork 184
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 UnitsFormatter
#5000
Implement UnitsFormatter
#5000
Conversation
Narrow, | ||
} | ||
|
||
impl Default for Width { |
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.
TODO: younies, what is the default width for units ?
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.
short
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: annotate the default variant with #[default]
and then use derive(Default)
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.
^ this is not done
pub fn format_fixed_decimal<'l>( | ||
&'l self, | ||
value: &'l FixedDecimal, | ||
unit: MeasureUnit, |
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.
Shall we allow the user to set the unit as MeasureUnit
or as &str
, in case that the user is going to be allowed to set the unit as MeasureUnit
, shall we upstream the MeasureUnit
in its own crate?
#[cfg(feature = "compiled_data")] | ||
/// Baked data | ||
/// | ||
/// <div class="stab unstable"> | ||
/// 🚧 This code is considered unstable; it may change at any time, in breaking or non-breaking ways, | ||
/// including in SemVer minor releases. In particular, the `DataProvider` implementations are only | ||
/// guaranteed to match with this version's `*_unstable` providers. Use with caution. | ||
/// </div> | ||
pub use crate::provider::Baked; | ||
|
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: Unrelated change
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, removed
let unit_pattern = "{0} ".to_owned() + self.unit; | ||
let display_name = match self.options.width { | ||
Width::Short => self.display_name.short.get(&count), | ||
Width::Long => self.display_name.long.get(&count), | ||
Width::Narrow => self.display_name.narrow.get(&count), | ||
} | ||
.unwrap_or({ unit_pattern.as_str() }); |
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: put the "{0} ".to_owned() + self.unit
inside unwrap_or_else
so we don't need to do it each time. Actually, we should just avoid this entirely by making the data struct required to include at least one entry. See example in https://github.com/unicode-org/icu4x/blob/main/documents/design/data_safety.md
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, thanks for the advice :)
try_new_with_any_provider, | ||
try_new_with_buffer_provider, |
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.
Thought: Technically cross-crate constructors should use custom logic, but let's not worry about that at the time being because it's a little annoying
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, I will keep this in mind
Narrow, | ||
} | ||
|
||
impl Default for Width { |
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: annotate the default variant with #[default]
and then use derive(Default)
Co-authored-by: Shane F. Carr <shane@unicode.org>
Co-authored-by: Shane F. Carr <shane@unicode.org>
Narrow, | ||
} | ||
|
||
impl Default for Width { |
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.
^ this is not done
let pattern = | ||
SinglePlaceholderPattern::from_str(display_name).map_err(|_| core::fmt::Error)?; |
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: Please add a TODO
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
Co-authored-by: Shane F. Carr <shane@unicode.org>
…ev-units-formatter
No description provided.