Skip to content

Commit

Permalink
Make some options bags have optional fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Sep 4, 2024
1 parent 375029a commit 381f85c
Show file tree
Hide file tree
Showing 11 changed files with 115 additions and 323 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,10 @@ icu_benchmark_macros = { path = "tools/benchmark/macros" }

# The version here can either be a `version = ".."` spec or `git = "https://github.com/rust-diplomat/diplomat", rev = ".."`
# Diplomat must be published preceding a new ICU4X release but may use git versions in between
diplomat = { git = "https://github.com/rust-diplomat/diplomat", rev = "6807b4a92f3f8a6dd565d044b2e2fac181fc997f" }
diplomat-runtime = { git = "https://github.com/rust-diplomat/diplomat", rev = "6807b4a92f3f8a6dd565d044b2e2fac181fc997f" }
diplomat_core = { git = "https://github.com/rust-diplomat/diplomat", rev = "6807b4a92f3f8a6dd565d044b2e2fac181fc997f" }
diplomat-tool = { git = "https://github.com/rust-diplomat/diplomat", rev = "6807b4a92f3f8a6dd565d044b2e2fac181fc997f" }
diplomat = { git = "https://github.com/rust-diplomat/diplomat", rev = "fe5201dd04ee6614942f817b291e90cb01440c19" }
diplomat-runtime = { git = "https://github.com/rust-diplomat/diplomat", rev = "fe5201dd04ee6614942f817b291e90cb01440c19" }
diplomat_core = { git = "https://github.com/rust-diplomat/diplomat", rev = "fe5201dd04ee6614942f817b291e90cb01440c19" }
diplomat-tool = { git = "https://github.com/rust-diplomat/diplomat", rev = "fe5201dd04ee6614942f817b291e90cb01440c19" }

# EXTERNAL DEPENDENCIES
#
Expand Down
10 changes: 5 additions & 5 deletions ffi/capi/src/bidi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub mod ffi {

/// Use the data loaded in this object to process a string and calculate bidi information
///
/// Takes in a Level for the default level, if it is an invalid value it will default to LTR
/// Takes in a Level for the default level, if it is an invalid value or None it will default to Auto.
///
/// Returns nothing if `text` is invalid UTF-8.
#[diplomat::rust_link(unicode_bidi::BidiInfo::new_with_data_source, FnInStruct)]
Expand All @@ -53,7 +53,7 @@ pub mod ffi {
pub fn for_text_utf8<'text>(
&self,
text: &'text DiplomatStr,
default_level: u8,
default_level: Option<u8>,
) -> Option<Box<BidiInfo<'text>>> {
let text = core::str::from_utf8(text).ok()?;

Expand All @@ -64,7 +64,7 @@ pub mod ffi {
unicode_bidi::BidiInfo::new_with_data_source(
&adapter,
text,
unicode_bidi::Level::new(default_level).ok(),
default_level.and_then(|l| unicode_bidi::Level::new(l).ok()),
),
)))
}
Expand All @@ -84,15 +84,15 @@ pub mod ffi {
pub fn for_text_valid_utf8<'text>(
&self,
text: &'text str,
default_level: u8,
default_level: Option<u8>,
) -> Box<BidiInfo<'text>> {
let data = self.0.as_borrowed();
let adapter = icu_properties::bidi::BidiClassAdapter::new(data);

Box::new(BidiInfo(unicode_bidi::BidiInfo::new_with_data_source(
&adapter,
text,
unicode_bidi::Level::new(default_level).ok(),
default_level.and_then(|l| unicode_bidi::Level::new(l).ok()),
)))
}

Expand Down
17 changes: 11 additions & 6 deletions ffi/capi/src/casemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub mod ffi {
use alloc::boxed::Box;

use crate::{errors::ffi::DataError, locale_core::ffi::Locale, provider::ffi::DataProvider};
use diplomat_runtime::DiplomatOption;

use writeable::Writeable;

Expand All @@ -32,8 +33,8 @@ pub mod ffi {
#[diplomat::rust_link(icu::casemap::titlecase::TitlecaseOptions, Struct)]
#[diplomat::attr(supports = non_exhaustive_structs, rename = "TitlecaseOptions")]
pub struct TitlecaseOptionsV1 {
pub leading_adjustment: LeadingAdjustment,
pub trailing_case: TrailingCase,
pub leading_adjustment: DiplomatOption<LeadingAdjustment>,
pub trailing_case: DiplomatOption<TrailingCase>,
}

impl TitlecaseOptionsV1 {
Expand All @@ -42,8 +43,8 @@ pub mod ffi {
#[diplomat::attr(any(cpp, js), rename = "default_options")]
pub fn default() -> TitlecaseOptionsV1 {
Self {
leading_adjustment: LeadingAdjustment::Auto,
trailing_case: TrailingCase::Lower,
leading_adjustment: None.into(),
trailing_case: None.into(),
}
}
}
Expand Down Expand Up @@ -300,8 +301,12 @@ impl From<ffi::TitlecaseOptionsV1> for TitlecaseOptions {
fn from(other: ffi::TitlecaseOptionsV1) -> Self {
let mut ret = Self::default();

ret.leading_adjustment = other.leading_adjustment.into();
ret.trailing_case = other.trailing_case.into();
if let Some(l) = other.leading_adjustment.into_converted_option() {
ret.leading_adjustment = l;
}
if let Some(t) = other.trailing_case.into_converted_option() {
ret.trailing_case = t;
}
ret
}
}
Loading

0 comments on commit 381f85c

Please sign in to comment.