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

refactor: Derive Default for enums #356

Merged
merged 1 commit into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions fluent-bundle/examples/custom_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,16 @@ use fluent_bundle::{FluentArgs, FluentBundle, FluentResource, FluentValue};
// - timeStyle
//
// with an enum of allowed values.
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
#[derive(Debug, Default, PartialEq, Eq, Clone, Hash)]
enum DateTimeStyleValue {
Full,
Long,
Medium,
Short,
#[default]
None,
}

impl std::default::Default for DateTimeStyleValue {
fn default() -> Self {
Self::None
}
}

// This is just a helper to make it easier to convert
// a value provided to FluentArgs into an option value.
impl<'l> From<&FluentValue<'l>> for DateTimeStyleValue {
Expand Down
18 changes: 4 additions & 14 deletions fluent-bundle/src/types/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,14 @@ use intl_pluralrules::operands::PluralOperands;
use crate::args::FluentArgs;
use crate::types::FluentValue;

#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
#[derive(Debug, Copy, Clone, Default, Hash, PartialEq, Eq)]
pub enum FluentNumberStyle {
#[default]
Decimal,
Currency,
Percent,
}

impl std::default::Default for FluentNumberStyle {
fn default() -> Self {
Self::Decimal
}
}

impl From<&str> for FluentNumberStyle {
fn from(input: &str) -> Self {
match input {
Expand All @@ -32,19 +27,14 @@ impl From<&str> for FluentNumberStyle {
}
}

#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
#[derive(Debug, Copy, Clone, Default, Hash, PartialEq, Eq)]
pub enum FluentNumberCurrencyDisplayStyle {
#[default]
Symbol,
Code,
Name,
}

impl std::default::Default for FluentNumberCurrencyDisplayStyle {
fn default() -> Self {
Self::Symbol
}
}

impl From<&str> for FluentNumberCurrencyDisplayStyle {
fn from(input: &str) -> Self {
match input {
Expand Down
9 changes: 2 additions & 7 deletions fluent-bundle/tests/custom_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,16 @@ fn fluent_custom_type() {

#[test]
fn fluent_date_time_builtin() {
#[derive(Debug, PartialEq, Clone)]
#[derive(Debug, Default, PartialEq, Clone)]
enum DateTimeStyleValue {
Full,
Long,
Medium,
Short,
#[default]
None,
}

impl std::default::Default for DateTimeStyleValue {
fn default() -> Self {
Self::None
}
}

impl<'l> From<&FluentValue<'l>> for DateTimeStyleValue {
fn from(input: &FluentValue) -> Self {
if let FluentValue::String(s) = input {
Expand Down