diff --git a/ffi/capi/src/locale_directionality.rs b/ffi/capi/src/locale_directionality.rs index ae72bad9e28..78b7851da95 100644 --- a/ffi/capi/src/locale_directionality.rs +++ b/ffi/capi/src/locale_directionality.rs @@ -71,23 +71,13 @@ pub mod ffi { DataProviderInner::Destroyed => Err(icu_provider::DataError::custom( "This provider has been destroyed", ))?, - DataProviderInner::Empty => { - icu_locale::LocaleDirectionality::try_new_with_expander_unstable( - &icu_provider_adapters::empty::EmptyDataProvider::new(), - expander.0.clone(), - )? - } - #[cfg(feature = "buffer_provider")] + DataProviderInner::Buffer(buffer_provider) => { icu_locale::LocaleDirectionality::try_new_with_expander_unstable( &buffer_provider.as_deserializing(), expander.0.clone(), )? } - #[cfg(feature = "compiled_data")] - DataProviderInner::Compiled => { - icu_locale::LocaleDirectionality::new_with_expander(expander.0.clone()) - } }))) } diff --git a/ffi/capi/src/provider.rs b/ffi/capi/src/provider.rs index b74086ad7a2..372c75f982a 100644 --- a/ffi/capi/src/provider.rs +++ b/ffi/capi/src/provider.rs @@ -2,20 +2,19 @@ // called LICENSE at the top level of the ICU4X source tree // (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). +#[cfg(feature = "buffer_provider")] use icu_provider::prelude::*; +#[cfg(feature = "buffer_provider")] pub enum DataProviderInner { Destroyed, - Empty, - #[cfg(feature = "compiled_data")] - Compiled, - #[cfg(feature = "buffer_provider")] Buffer(alloc::boxed::Box), } #[diplomat::bridge] #[diplomat::abi_rename = "icu4x_{0}_mv1"] #[diplomat::attr(auto, namespace = "icu4x")] +#[cfg(feature = "buffer_provider")] pub mod ffi { use alloc::boxed::Box; @@ -27,7 +26,6 @@ pub mod ffi { #[diplomat::rust_link(icu_provider, Mod)] pub struct DataProvider(pub DataProviderInner); - #[cfg(feature = "buffer_provider")] fn convert_buffer_provider( x: D, ) -> DataProvider { @@ -35,19 +33,6 @@ pub mod ffi { } impl DataProvider { - /// Constructs an [`DataProvider`] that uses compiled data. - /// - /// Requires the `compiled_data` feature. - /// - /// This provider cannot be modified or combined with other providers, so `enable_fallback`, - /// `enabled_fallback_with`, `fork_by_locale`, and `fork_by_key` will return `Err`s. - #[cfg(feature = "compiled_data")] - #[diplomat::attr(auto, named_constructor)] - #[diplomat::demo(default_constructor)] - pub fn compiled() -> Box { - Box::new(Self(DataProviderInner::Compiled)) - } - /// Constructs an `FsDataProvider` and returns it as an [`DataProvider`]. /// Requires the `provider_fs` Cargo feature. /// Not supported in WASM. @@ -71,7 +56,6 @@ pub mod ffi { /// Constructs a `BlobDataProvider` and returns it as an [`DataProvider`]. #[diplomat::rust_link(icu_provider_blob::BlobDataProvider, Struct)] - #[cfg(feature = "buffer_provider")] #[diplomat::attr(supports = fallible_constructors, named_constructor)] #[diplomat::attr(not(supports = static_slices), disable)] pub fn from_byte_slice( @@ -82,18 +66,6 @@ pub mod ffi { ))) } - /// Constructs an empty [`DataProvider`]. - #[diplomat::rust_link(icu_provider_adapters::empty::EmptyDataProvider, Struct)] - #[diplomat::rust_link( - icu_provider_adapters::empty::EmptyDataProvider::new, - FnInStruct, - hidden - )] - #[diplomat::attr(auto, named_constructor)] - pub fn empty() -> Box { - Box::new(DataProvider(DataProviderInner::Empty)) - } - /// Creates a provider that tries the current provider and then, if the current provider /// doesn't support the data key, another provider `other`. /// @@ -118,14 +90,6 @@ pub mod ffi { (Destroyed, _) | (_, Destroyed) => Err(icu_provider::DataError::custom( "This provider has been destroyed", ))?, - #[cfg(feature = "compiled_data")] - (Compiled, _) | (_, Compiled) => Err(icu_provider::DataError::custom( - "The compiled provider cannot be modified", - ))?, - (Empty, Empty) => DataProvider(DataProviderInner::Empty), - #[cfg(feature = "buffer_provider")] - (Empty, b) | (b, Empty) => DataProvider(b), - #[cfg(feature = "buffer_provider")] (Buffer(a), Buffer(b)) => convert_buffer_provider( icu_provider_adapters::fork::ForkByMarkerProvider::new(a, b), ), @@ -148,14 +112,6 @@ pub mod ffi { (Destroyed, _) | (_, Destroyed) => Err(icu_provider::DataError::custom( "This provider has been destroyed", ))?, - #[cfg(feature = "compiled_data")] - (Compiled, _) | (_, Compiled) => Err(icu_provider::DataError::custom( - "The compiled provider cannot be modified", - ))?, - (Empty, Empty) => DataProvider(DataProviderInner::Empty), - #[cfg(feature = "buffer_provider")] - (Empty, b) | (b, Empty) => DataProvider(b), - #[cfg(feature = "buffer_provider")] (Buffer(a), Buffer(b)) => convert_buffer_provider( icu_provider_adapters::fork::ForkByErrorProvider::new_with_predicate( a, @@ -187,12 +143,6 @@ pub mod ffi { Destroyed => Err(icu_provider::DataError::custom( "This provider has been destroyed", ))?, - #[cfg(feature = "compiled_data")] - Compiled => Err(icu_provider::DataError::custom( - "The compiled provider cannot be modified", - ))?, - Empty => Err(icu_provider::DataErrorKind::MarkerNotFound.into_error())?, - #[cfg(feature = "buffer_provider")] Buffer(inner) => convert_buffer_provider( icu_provider_adapters::fallback::LocaleFallbackProvider::new( inner, @@ -205,30 +155,20 @@ pub mod ffi { } } +#[cfg(feature = "buffer_provider")] macro_rules! load { () => { fn load(&self, req: DataRequest) -> Result, DataError> { use DataProviderInner::*; match self { Destroyed => Err(DataError::custom("This provider has been destroyed"))?, - Empty => icu_provider_adapters::empty::EmptyDataProvider::new().load(req), #[cfg(feature = "buffer_provider")] Buffer(buffer_provider) => buffer_provider.as_deserializing().load(req), - #[cfg(feature = "compiled_data")] - Compiled => unreachable!(), } } }; } -#[cfg(not(feature = "buffer_provider"))] -impl DataProvider for DataProviderInner -where - M: DataMarker, -{ - load!(); -} - #[cfg(feature = "buffer_provider")] impl DataProvider for DataProviderInner where @@ -250,16 +190,6 @@ macro_rules! call_constructor { "This provider has been destroyed", ))?, $crate::provider::DataProviderInner::Buffer(buffer_provider) => $buffer(buffer_provider, $($args,)*), - _ => unreachable!() - } - }; - ($buffer:path, $provider:expr $(, $args:expr)* $(,)?) => { - match &$provider.0 { - $crate::provider::DataProviderInner::Destroyed => Err(icu_provider::DataError::custom( - "This provider has been destroyed", - ))?, - $crate::provider::DataProviderInner::Buffer(buffer_provider) => $buffer(buffer_provider, $($args,)*), - _ => unreachable!() } }; } @@ -272,16 +202,6 @@ macro_rules! call_constructor_unstable { "This provider has been destroyed", ))?, $crate::provider::DataProviderInner::Buffer(buffer_provider) => $unstable(&icu_provider::buf::AsDeserializingBufferProvider::as_deserializing(buffer_provider), $($args,)*), - _ => unreachable!() - } - }; - ($unstable:path, $provider:expr $(, $args:expr)* $(,)?) => { - match &$provider.0 { - $crate::provider::DataProviderInner::Destroyed => Err(icu_provider::DataError::custom( - "This provider has been destroyed", - ))?, - $crate::provider::DataProviderInner::Buffer(buffer_provider) => $unstable(&icu_provider::buf::AsDeserializingBufferProvider::as_deserializing(buffer_provider), $($args,)*), - _ => unreachable!() } }; }