diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:18:32 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:18:32 +0000 |
commit | 4547b622d8d29df964fa2914213088b148c498fc (patch) | |
tree | 9fc6b25f3c3add6b745be9a2400a6e96140046e9 /vendor/icu_provider/src/datagen/data_conversion.rs | |
parent | Releasing progress-linux version 1.66.0+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-4547b622d8d29df964fa2914213088b148c498fc.tar.xz rustc-4547b622d8d29df964fa2914213088b148c498fc.zip |
Merging upstream version 1.67.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/icu_provider/src/datagen/data_conversion.rs')
-rw-r--r-- | vendor/icu_provider/src/datagen/data_conversion.rs | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/vendor/icu_provider/src/datagen/data_conversion.rs b/vendor/icu_provider/src/datagen/data_conversion.rs new file mode 100644 index 000000000..59146352a --- /dev/null +++ b/vendor/icu_provider/src/datagen/data_conversion.rs @@ -0,0 +1,48 @@ +// This file is part of ICU4X. For terms of use, please see the file +// called LICENSE at the top level of the ICU4X source tree +// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). + +use crate::prelude::*; +use crate::DataKey; +use alloc::boxed::Box; + +/// A trait that allows for converting between data payloads of different types. +/// +/// These payloads will typically be some kind of erased payload, either with +/// AnyMarker, BufferMarker, or SerializeMarker, where converting requires reifying the type. +/// A type implementing [`DataConverter`] will essentially have a "registry" mapping keys to +/// concrete marker types M, and reifying the input to a `DataPayload<M>`, performing some conversion +/// or computation, and erasing the result to `DataPayload<MTo>`. +/// +/// It will typically be implemented on data providers used in datagen. +/// +/// The [`make_exportable_provider!`] macro is able to automatically implement this trait. +/// +/// [`make_exportable_provider!`]: crate::make_exportable_provider +pub trait DataConverter<MFrom: DataMarker, MTo: DataMarker> { + /// Attempt to convert a payload corresponding to the given data key + /// from one marker type to another marker type. + /// + /// If this is not possible (for example, if the provider does not know about the key), + /// the original payload is returned back to the caller. + fn convert( + &self, + key: DataKey, + from: DataPayload<MFrom>, + ) -> Result<DataPayload<MTo>, (DataPayload<MFrom>, DataError)>; +} + +impl<MFrom, MTo, P> DataConverter<MFrom, MTo> for Box<P> +where + MFrom: DataMarker, + MTo: DataMarker, + P: DataConverter<MFrom, MTo> + ?Sized, +{ + fn convert( + &self, + key: DataKey, + from: DataPayload<MFrom>, + ) -> Result<DataPayload<MTo>, (DataPayload<MFrom>, DataError)> { + (**self).convert(key, from) + } +} |