#[diplomat::bridge]
#[diplomat::abi_rename = "icu4x_{0}_mv1"]
#[diplomat::attr(auto, namespace = "icu4x")]
pub mod ffi {
use alloc::boxed::Box;
use crate::errors::ffi::DataError;
use crate::properties_iter::ffi::CodePointRangeIterator;
use crate::properties_sets::ffi::CodePointSetData;
use crate::provider::ffi::DataProvider;
#[diplomat::opaque]
#[diplomat::rust_link(icu::properties::script::ScriptWithExtensions, Struct)]
pub struct ScriptWithExtensions(pub icu_properties::script::ScriptWithExtensions);
#[diplomat::opaque]
#[diplomat::rust_link(icu::properties::script::ScriptWithExtensionsBorrowed, Struct)]
pub struct ScriptWithExtensionsBorrowed<'a>(
pub icu_properties::script::ScriptWithExtensionsBorrowed<'a>,
);
#[diplomat::opaque]
#[diplomat::rust_link(icu::properties::script::ScriptExtensionsSet, Struct)]
pub struct ScriptExtensionsSet<'a>(pub icu_properties::script::ScriptExtensionsSet<'a>);
impl ScriptWithExtensions {
#[diplomat::rust_link(icu::properties::script::ScriptWithExtensions::new, FnInStruct)]
#[diplomat::rust_link(
icu::properties::script::ScriptWithExtensionsBorrowed::new,
FnInStruct,
hidden
)]
#[diplomat::attr(supports = fallible_constructors, constructor)]
pub fn create(provider: &DataProvider) -> Result<Box<ScriptWithExtensions>, DataError> {
Ok(Box::new(ScriptWithExtensions(call_constructor!(
icu_properties::script::ScriptWithExtensions::new [r => Ok(r.static_to_owned())],
icu_properties::script::ScriptWithExtensions::try_new_with_any_provider,
icu_properties::script::ScriptWithExtensions::try_new_with_buffer_provider,
provider
)?)))
}
#[diplomat::rust_link(
icu::properties::script::ScriptWithExtensionsBorrowed::get_script_val,
FnInStruct
)]
#[diplomat::rust_link(
icu::properties::script::ScriptWithExtensionsBorrowed::get_script_val32,
FnInStruct,
hidden
)]
pub fn get_script_val(&self, ch: DiplomatChar) -> u16 {
self.0.as_borrowed().get_script_val32(ch).0
}
#[diplomat::rust_link(
icu::properties::script::ScriptWithExtensionsBorrowed::has_script,
FnInStruct
)]
#[diplomat::rust_link(
icu::properties::script::ScriptWithExtensionsBorrowed::has_script32,
FnInStruct,
hidden
)]
pub fn has_script(&self, ch: DiplomatChar, script: u16) -> bool {
self.0
.as_borrowed()
.has_script32(ch, icu_properties::props::Script(script))
}
#[diplomat::rust_link(
icu::properties::script::ScriptWithExtensions::as_borrowed,
FnInStruct
)]
#[diplomat::attr(auto, getter)]
pub fn as_borrowed<'a>(&'a self) -> Box<ScriptWithExtensionsBorrowed<'a>> {
Box::new(ScriptWithExtensionsBorrowed(self.0.as_borrowed()))
}
#[diplomat::rust_link(
icu::properties::script::ScriptWithExtensionsBorrowed::get_script_extensions_ranges,
FnInStruct
)]
pub fn iter_ranges_for_script<'a>(
&'a self,
script: u16,
) -> Box<CodePointRangeIterator<'a>> {
Box::new(CodePointRangeIterator(Box::new(
self.0
.as_borrowed()
.get_script_extensions_ranges(icu_properties::props::Script(script)),
)))
}
}
impl<'a> ScriptWithExtensionsBorrowed<'a> {
#[diplomat::rust_link(
icu::properties::script::ScriptWithExtensionsBorrowed::get_script_val,
FnInStruct
)]
#[diplomat::rust_link(
icu::properties::script::ScriptWithExtensionsBorrowed::get_script_val32,
FnInStruct,
hidden
)]
pub fn get_script_val(&self, ch: DiplomatChar) -> u16 {
self.0.get_script_val32(ch).0
}
#[diplomat::rust_link(
icu::properties::script::ScriptWithExtensionsBorrowed::get_script_extensions_val,
FnInStruct
)]
#[diplomat::rust_link(
icu::properties::script::ScriptWithExtensionsBorrowed::get_script_extensions_val32,
FnInStruct,
hidden
)]
pub fn get_script_extensions_val(&self, ch: DiplomatChar) -> Box<ScriptExtensionsSet<'a>> {
Box::new(ScriptExtensionsSet(self.0.get_script_extensions_val32(ch)))
}
#[diplomat::rust_link(
icu::properties::script::ScriptWithExtensionsBorrowed::has_script,
FnInStruct
)]
#[diplomat::rust_link(
icu::properties::script::ScriptWithExtensionsBorrowed::has_script32,
FnInStruct,
hidden
)]
pub fn has_script(&self, ch: DiplomatChar, script: u16) -> bool {
self.0
.has_script32(ch, icu_properties::props::Script(script))
}
#[diplomat::rust_link(
icu::properties::script::ScriptWithExtensionsBorrowed::get_script_extensions_set,
FnInStruct
)]
pub fn get_script_extensions_set(&self, script: u16) -> Box<CodePointSetData> {
let list = self
.0
.get_script_extensions_set(icu_properties::props::Script(script))
.into_owned();
let set = icu_properties::CodePointSetData::from_code_point_inversion_list(list);
Box::new(CodePointSetData(set))
}
}
impl<'a> ScriptExtensionsSet<'a> {
#[diplomat::rust_link(icu::properties::script::ScriptExtensionsSet::contains, FnInStruct)]
pub fn contains(&self, script: u16) -> bool {
self.0.contains(&icu_properties::props::Script(script))
}
#[diplomat::rust_link(icu::properties::script::ScriptExtensionsSet::iter, FnInStruct)]
#[diplomat::attr(auto, getter)]
pub fn count(&self) -> usize {
self.0.array_len()
}
#[diplomat::rust_link(icu::properties::script::ScriptExtensionsSet::iter, FnInStruct)]
pub fn script_at(&self, index: usize) -> Option<u16> {
self.0.array_get(index).map(|x| x.0)
}
}
}