Skip to content

Commit

Permalink
refactor: Derive Default for enums (#356)
Browse files Browse the repository at this point in the history
  • Loading branch information
waywardmonkeys authored May 6, 2024
1 parent eca819a commit 704e4ae
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 28 deletions.
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

0 comments on commit 704e4ae

Please sign in to comment.