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

Implement UnitsFormatter #5000

Merged
merged 31 commits into from
Jun 27, 2024
Merged

Conversation

younies
Copy link
Member

@younies younies commented Jun 4, 2024

No description provided.

Narrow,
}

impl Default for Width {
Copy link
Member Author

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 ?

Copy link
Member Author

Choose a reason for hiding this comment

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

short

Copy link
Member

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)

Copy link
Member

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,
Copy link
Member Author

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?

@younies younies changed the title Implement Units Formatter Implement UnitsFormatter Jun 27, 2024
@younies younies marked this pull request as ready for review June 27, 2024 14:52
@younies younies requested a review from a team as a code owner June 27, 2024 14:52
@younies younies requested a review from sffc June 27, 2024 14:52
Comment on lines 16 to 25
#[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;

Copy link
Member

Choose a reason for hiding this comment

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

Issue: Unrelated change

Copy link
Member Author

Choose a reason for hiding this comment

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

done, removed

Comment on lines 36 to 42
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() });
Copy link
Member

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

Copy link
Member Author

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 :)

components/experimental/src/dimension/units/format.rs Outdated Show resolved Hide resolved
components/experimental/src/dimension/units/formatter.rs Outdated Show resolved Hide resolved
Comment on lines +49 to +50
try_new_with_any_provider,
try_new_with_buffer_provider,
Copy link
Member

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

Copy link
Member Author

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 {
Copy link
Member

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)

@younies younies requested a review from sffc June 27, 2024 15:30
provider/bikeshed/src/units/data.rs Outdated Show resolved Hide resolved
Narrow,
}

impl Default for Width {
Copy link
Member

Choose a reason for hiding this comment

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

^ this is not done

Comment on lines +44 to +45
let pattern =
SinglePlaceholderPattern::from_str(display_name).map_err(|_| core::fmt::Error)?;
Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@younies younies requested a review from sffc June 27, 2024 16:17
@younies younies merged commit 8f2f35d into unicode-org:main Jun 27, 2024
28 checks passed
@younies younies deleted the dev-units-formatter branch June 27, 2024 17:18
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