#[diplomat::bridge]
#[diplomat::abi_rename = "icu4x_{0}_mv1"]
#[diplomat::attr(auto, namespace = "icu4x")]
pub mod ffi {
use alloc::boxed::Box;
#[cfg(feature = "buffer_provider")]
use crate::{errors::ffi::DataError, provider::ffi::DataProvider};
#[diplomat::opaque]
#[diplomat::rust_link(icu::normalizer::properties::CanonicalCombiningClassMap, Struct)]
#[diplomat::rust_link(
icu::normalizer::properties::CanonicalCombiningClassMapBorrowed,
Struct,
hidden
)]
pub struct CanonicalCombiningClassMap(
pub icu_normalizer::properties::CanonicalCombiningClassMap,
);
impl CanonicalCombiningClassMap {
#[diplomat::rust_link(
icu::normalizer::properties::CanonicalCombiningClassMap::new,
FnInStruct
)]
#[diplomat::rust_link(
icu::normalizer::properties::CanonicalCombiningClassMapBorrowed::new,
FnInStruct,
hidden
)]
#[diplomat::attr(auto, constructor)]
#[cfg(feature = "compiled_data")]
pub fn create() -> Box<CanonicalCombiningClassMap> {
Box::new(CanonicalCombiningClassMap(
icu_normalizer::properties::CanonicalCombiningClassMap::new().static_to_owned(),
))
}
#[diplomat::rust_link(
icu::normalizer::properties::CanonicalCombiningClassMap::new,
FnInStruct
)]
#[diplomat::rust_link(
icu::normalizer::properties::CanonicalCombiningClassMapBorrowed::new,
FnInStruct,
hidden
)]
#[diplomat::attr(supports = fallible_constructors, named_constructor = "with_provider")]
#[cfg(feature = "buffer_provider")]
pub fn create_with_provider(
provider: &DataProvider,
) -> Result<Box<CanonicalCombiningClassMap>, DataError> {
Ok(Box::new(CanonicalCombiningClassMap(provider.call_constructor(icu_normalizer::properties::CanonicalCombiningClassMap::try_new_with_buffer_provider)?)))
}
#[diplomat::rust_link(
icu::normalizer::properties::CanonicalCombiningClassMapBorrowed::get,
FnInStruct
)]
#[diplomat::rust_link(
icu::normalizer::properties::CanonicalCombiningClassMapBorrowed::get32,
FnInStruct,
hidden
)]
#[diplomat::rust_link(
icu::normalizer::properties::CanonicalCombiningClassMapBorrowed::get32_u8,
FnInStruct,
hidden
)]
#[diplomat::rust_link(
icu::normalizer::properties::CanonicalCombiningClassMapBorrowed::get_u8,
FnInStruct,
hidden
)]
#[diplomat::rust_link(
icu::properties::properties::CanonicalCombiningClassMapBorrowed,
Struct,
compact
)]
#[diplomat::attr(auto, indexer)]
pub fn get(&self, ch: DiplomatChar) -> u8 {
self.0.as_borrowed().get32_u8(ch)
}
}
#[diplomat::opaque]
#[diplomat::rust_link(icu::normalizer::properties::CanonicalComposition, Struct)]
#[diplomat::rust_link(
icu::normalizer::properties::CanonicalCompositionBorrowed,
Struct,
hidden
)]
pub struct CanonicalComposition(pub icu_normalizer::properties::CanonicalComposition);
impl CanonicalComposition {
#[diplomat::rust_link(icu::normalizer::properties::CanonicalComposition::new, FnInStruct)]
#[diplomat::rust_link(
icu::normalizer::properties::CanonicalCompositionBorrowed::new,
FnInStruct,
hidden
)]
#[diplomat::attr(auto, constructor)]
#[cfg(feature = "compiled_data")]
pub fn create() -> Box<CanonicalComposition> {
Box::new(CanonicalComposition(
icu_normalizer::properties::CanonicalComposition::new().static_to_owned(),
))
}
#[diplomat::rust_link(icu::normalizer::properties::CanonicalComposition::new, FnInStruct)]
#[diplomat::rust_link(
icu::normalizer::properties::CanonicalCompositionBorrowed::new,
FnInStruct,
hidden
)]
#[diplomat::attr(supports = fallible_constructors, named_constructor = "with_provider")]
#[cfg(feature = "buffer_provider")]
pub fn create_with_provider(
provider: &DataProvider,
) -> Result<Box<CanonicalComposition>, DataError> {
Ok(Box::new(CanonicalComposition(provider.call_constructor(
|provider| {
icu_normalizer::properties::CanonicalComposition::try_new_with_buffer_provider(
provider,
)
},
)?)))
}
#[diplomat::rust_link(
icu::normalizer::properties::CanonicalCompositionBorrowed::compose,
FnInStruct
)]
pub fn compose(&self, starter: DiplomatChar, second: DiplomatChar) -> DiplomatChar {
match (char::from_u32(starter), char::from_u32(second)) {
(Some(starter), Some(second)) => self.0.as_borrowed().compose(starter, second),
_ => None,
}
.unwrap_or('\0') as DiplomatChar
}
}
#[diplomat::rust_link(icu::normalizer::properties::Decomposed, Enum)]
#[diplomat::out]
pub struct Decomposed {
first: DiplomatChar,
second: DiplomatChar,
}
#[diplomat::opaque]
#[diplomat::rust_link(icu::normalizer::properties::CanonicalDecomposition, Struct)]
#[diplomat::rust_link(
icu::normalizer::properties::CanonicalDecompositionBorrowed,
Struct,
hidden
)]
pub struct CanonicalDecomposition(pub icu_normalizer::properties::CanonicalDecomposition);
impl CanonicalDecomposition {
#[diplomat::rust_link(icu::normalizer::properties::CanonicalDecomposition::new, FnInStruct)]
#[diplomat::rust_link(
icu::normalizer::properties::CanonicalDecompositionBorrowed::new,
FnInStruct,
hidden
)]
#[diplomat::attr(auto, constructor)]
#[cfg(feature = "compiled_data")]
pub fn create() -> Box<CanonicalDecomposition> {
Box::new(CanonicalDecomposition(
icu_normalizer::properties::CanonicalDecomposition::new().static_to_owned(),
))
}
#[diplomat::rust_link(icu::normalizer::properties::CanonicalDecomposition::new, FnInStruct)]
#[diplomat::rust_link(
icu::normalizer::properties::CanonicalDecompositionBorrowed::new,
FnInStruct,
hidden
)]
#[diplomat::attr(supports = fallible_constructors, named_constructor = "with_provider")]
#[cfg(feature = "buffer_provider")]
pub fn create_with_provider(
provider: &DataProvider,
) -> Result<Box<CanonicalDecomposition>, DataError> {
Ok(Box::new(CanonicalDecomposition(provider.call_constructor(icu_normalizer::properties::CanonicalDecomposition::try_new_with_buffer_provider)?)))
}
#[diplomat::rust_link(
icu::normalizer::properties::CanonicalDecompositionBorrowed::decompose,
FnInStruct
)]
pub fn decompose(&self, c: DiplomatChar) -> Decomposed {
match char::from_u32(c) {
Some(c) => match self.0.as_borrowed().decompose(c) {
icu_normalizer::properties::Decomposed::Default => Decomposed {
first: c as DiplomatChar,
second: '\0' as DiplomatChar,
},
icu_normalizer::properties::Decomposed::Singleton(s) => Decomposed {
first: s as DiplomatChar,
second: '\0' as DiplomatChar,
},
icu_normalizer::properties::Decomposed::Expansion(first, second) => {
Decomposed {
first: first as DiplomatChar,
second: second as DiplomatChar,
}
}
},
_ => Decomposed {
first: c,
second: '\0' as DiplomatChar,
},
}
}
}
}