//! This module contains types required to export ICU4X data via the `icu_provider_export` crate. //! End users should not need to consume anything in this module. //! //! This module is enabled with the `export` Cargo feature.
usecrate::prelude::*; use alloc::collections::BTreeSet;
/// An object capable of exporting data payloads in some form. pubtrait DataExporter: Sync { /// Save a `payload` corresponding to the given marker and locale. /// /// Takes non-mut self as it can be called concurrently. fn put_payload(
&self,
marker: DataMarkerInfo,
id: DataIdentifierBorrowed,
payload: &DataPayload<ExportMarker>,
) -> Result<(), DataError>;
/// Function called for singleton markers. /// /// Takes non-mut self as it can be called concurrently. fn flush_singleton(
&self,
marker: DataMarkerInfo,
payload: &DataPayload<ExportMarker>,
metadata: FlushMetadata,
) -> Result<(), DataError> { self.put_payload(marker, Default::default(), payload)?; self.flush(marker, metadata)
}
/// Function called after a non-singleton marker has been fully enumerated. /// /// Takes non-mut self as it can be called concurrently. fn flush(&self, _marker: DataMarkerInfo, _metadata: FlushMetadata) -> Result<(), DataError> {
Ok(())
}
/// This function has to be called before the object is dropped (after all /// markers have been fully dumped). This conceptually takes ownership, so /// clients *may not* interact with this object after close has been called. fn close(&mutself) -> Result<ExporterCloseMetadata, DataError> {
Ok(ExporterCloseMetadata::default())
}
}
#[derive(Debug, Default)] #[allow(clippy::exhaustive_structs)] // newtype /// Contains information about a successful export. pubstruct ExporterCloseMetadata(pub Option<Box<dyn core::any::Any>>);
/// Metadata for [`DataExporter::flush`] #[non_exhaustive] #[derive(Debug, Copy, Clone, Default)] pubstruct FlushMetadata { /// Whether the data was generated in such a way that a [`DryDataProvider`] implementation /// makes sense. pub supports_dry_provider: bool, /// The checksum to return with this data marker. pub checksum: Option<u64>,
}
/// A [`DynamicDataProvider`] that can be used for exporting data. /// /// Use [`make_exportable_provider`] to implement this. pubtrait ExportableProvider: crate::data_provider::IterableDynamicDataProvider<ExportMarker> + Sync
{ /// Returns the set of supported markers fn supported_markers(&self) -> BTreeSet<DataMarkerInfo>;
}
/// This macro can be used on a data provider to allow it to be exported by `ExportDriver`. /// /// Data generation 'compiles' data by using this data provider (which usually translates data from /// different sources and doesn't have to be efficient) to generate data structs, and then writing /// them to an efficient format like `BlobDataProvider` or `BakedDataProvider`. The requirements /// for `make_exportable_provider` are: /// * The data struct has to implement [`serde::Serialize`](::serde::Serialize) and [`databake::Bake`] /// * The provider needs to implement [`IterableDataProvider`] for all specified [`DataMarker`]s. /// This allows the generating code to know which [`DataIdentifierCow`]s to export. #[macro_export] #[doc(hidden)] // macro
macro_rules! __make_exportable_provider {
($provider:ty, [ $($(#[$cfg:meta])? $struct_m:ty),+, ]) => { impl $crate::export::ExportableProvider for $provider { fn supported_markers(&self) -> alloc::collections::BTreeSet<$crate::DataMarkerInfo> {
alloc::collections::BTreeSet::from_iter([
$(
$(#[$cfg])?
<$struct_m>::INFO,
)+
])
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.