diff options
Diffstat (limited to 'vendor/icu_provider/src/buf.rs')
-rw-r--r-- | vendor/icu_provider/src/buf.rs | 48 |
1 files changed, 37 insertions, 11 deletions
diff --git a/vendor/icu_provider/src/buf.rs b/vendor/icu_provider/src/buf.rs index 796ad32f3..5e8264998 100644 --- a/vendor/icu_provider/src/buf.rs +++ b/vendor/icu_provider/src/buf.rs @@ -11,6 +11,7 @@ use crate::prelude::*; /// The data is expected to be deserialized before it can be used; see /// [`DataPayload::into_deserialized`]. #[allow(clippy::exhaustive_structs)] // marker type +#[derive(Debug)] pub struct BufferMarker; impl DataMarker for BufferMarker { @@ -38,21 +39,46 @@ impl DataMarker for BufferMarker { /// use icu_locid::locale; /// use icu_provider::hello_world::*; /// use icu_provider::prelude::*; +/// use std::borrow::Cow; /// /// let buffer_provider = HelloWorldProvider.into_json_provider(); /// -/// let data_provider = buffer_provider.as_deserializing(); +/// let req = DataRequest { +/// locale: &locale!("de").into(), +/// metadata: Default::default(), +/// }; /// -/// let german_hello_world: DataPayload<HelloWorldV1Marker> = data_provider -/// .load(DataRequest { -/// locale: &locale!("de").into(), -/// metadata: Default::default(), -/// }) -/// .expect("Loading should succeed") -/// .take_payload() -/// .expect("Data should be present"); +/// // Deserializing manually +/// assert_eq!( +/// serde_json::from_slice::<HelloWorldV1>( +/// buffer_provider +/// .load_buffer(HelloWorldV1Marker::KEY, req) +/// .expect("load should succeed") +/// .take_payload() +/// .unwrap() +/// .get() +/// ) +/// .expect("should deserialize"), +/// HelloWorldV1 { +/// message: Cow::Borrowed("Hallo Welt"), +/// }, +/// ); /// -/// assert_eq!("Hallo Welt", german_hello_world.get().message); +/// // Deserialize automatically +/// let deserializing_provider: &dyn DataProvider<HelloWorldV1Marker> = +/// &buffer_provider.as_deserializing(); +/// +/// assert_eq!( +/// deserializing_provider +/// .load(req) +/// .expect("load should succeed") +/// .take_payload() +/// .unwrap() +/// .get(), +/// &HelloWorldV1 { +/// message: Cow::Borrowed("Hallo Welt"), +/// }, +/// ); /// # } /// ``` /// @@ -85,7 +111,7 @@ pub enum BufferFormat { Json, /// Serialize using Bincode version 1. Bincode1, - /// Serialize using Postcard version 0.7. + /// Serialize using Postcard version 1. Postcard1, } |