Skip to content

Commit

Permalink
Refactor to make code slightly prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
sffc committed Oct 20, 2023
1 parent d13b663 commit 3d39124
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 35 deletions.
19 changes: 19 additions & 0 deletions components/datetime/src/provider/calendar/symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,25 @@ macro_rules! symbols {
#[cfg_attr(feature = "serde", serde(borrow))]
pub stand_alone: Option<StandAloneWidthsV1<'data>>,
}

impl<'data> ContextsV1<'data> {
/// Convenience function to return stand-alone abbreviated as an `Option<&>`.
pub(crate) fn stand_alone_abbreviated(&self) -> Option<&SymbolsV1<'data>> {
self.stand_alone.as_ref().and_then(|x| x.abbreviated.as_ref())
}
/// Convenience function to return stand-alone wide as an `Option<&>`.
pub(crate) fn stand_alone_wide(&self) -> Option<&SymbolsV1<'data>> {
self.stand_alone.as_ref().and_then(|x| x.wide.as_ref())
}
/// Convenience function to return stand-alone narrow as an `Option<&>`.
pub(crate) fn stand_alone_narrow(&self) -> Option<&SymbolsV1<'data>> {
self.stand_alone.as_ref().and_then(|x| x.narrow.as_ref())
}
/// Convenience function to return stand-alone short as an `Option<&>`.
pub(crate) fn stand_alone_short(&self) -> Option<&SymbolsV1<'data>> {
self.stand_alone.as_ref().and_then(|x| x.short.as_ref())
}
}
}
};
}
Expand Down
42 changes: 7 additions & 35 deletions components/datetime/src/provider/neo/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,9 @@ where
let new_payload = payload.map_project_cloned(|payload, _| {
use subtag_consts::*;
let result = match subtag {
STADLN_ABBR => payload
.months
.stand_alone
.as_ref()
.and_then(|x| x.abbreviated.as_ref()),
STADLN_WIDE => payload
.months
.stand_alone
.as_ref()
.and_then(|x| x.wide.as_ref()),
STADLN_NARW => payload
.months
.stand_alone
.as_ref()
.and_then(|x| x.narrow.as_ref()),
STADLN_ABBR => payload.months.stand_alone_abbreviated(),
STADLN_WIDE => payload.months.stand_alone_wide(),
STADLN_NARW => payload.months.stand_alone_narrow(),
_ => None,
};
if let Some(result) = result {
Expand Down Expand Up @@ -87,26 +75,10 @@ where
let new_payload = payload.map_project_cloned(|payload, _| {
use subtag_consts::*;
let result = match subtag {
STADLN_ABBR => payload
.weekdays
.stand_alone
.as_ref()
.and_then(|x| x.abbreviated.as_ref()),
STADLN_WIDE => payload
.weekdays
.stand_alone
.as_ref()
.and_then(|x| x.wide.as_ref()),
STADLN_NARW => payload
.weekdays
.stand_alone
.as_ref()
.and_then(|x| x.narrow.as_ref()),
STADLN_SHRT => payload
.weekdays
.stand_alone
.as_ref()
.and_then(|x| x.short.as_ref()),
STADLN_ABBR => payload.weekdays.stand_alone_abbreviated(),
STADLN_WIDE => payload.weekdays.stand_alone_wide(),
STADLN_NARW => payload.weekdays.stand_alone_narrow(),
STADLN_SHRT => payload.weekdays.stand_alone_short(),
_ => None,
};
if let Some(result) = result {
Expand Down

0 comments on commit 3d39124

Please sign in to comment.