pub struct CompositeFieldSetSerde { /* private fields */ }
Expand description
🚧 [Experimental] A type corresponding to CompositeFieldSet
that implements
serde::Serialize
and serde::Deserialize
.
The serialized representation is subject to change.
🚧 This code is experimental; it may change at any time, in breaking or non-breaking ways,
including in SemVer minor releases. Use with caution.
#5825
§Examples
use icu::datetime::fieldset;
use icu::datetime::fieldset::dynamic::CompositeFieldSet;
use icu::datetime::fieldset::dynamic::DateFieldSet;
use icu::datetime::fieldset::serde::CompositeFieldSetSerde;
let field_set = CompositeFieldSet::Date(DateFieldSet::YMD(fieldset::YMD::short()));
let serde_input = CompositeFieldSetSerde::from(field_set);
let json_string = serde_json::to_string(&serde_input).unwrap();
assert_eq!(
json_string,
r#"{"fieldSet":["year","month","day"],"length":"short"}"#
);
let serde_output = serde_json::from_str::<CompositeFieldSetSerde>(&json_string).unwrap();
let deserialized = CompositeFieldSet::try_from(serde_output).unwrap();
assert_eq!(field_set, deserialized);
If the field set is invalid, an error will occur:
use icu::datetime::fieldset::dynamic::CompositeFieldSet;
use icu::datetime::fieldset::serde::CompositeFieldSetSerde;
use icu::datetime::fieldset::serde::CompositeFieldSetSerdeError;
let json_string = r#"{"fieldSet":["year","time"],"length":"short"}"#;
let serde_output = serde_json::from_str::<CompositeFieldSetSerde>(&json_string).unwrap();
assert!(matches!(
CompositeFieldSet::try_from(serde_output),
Err(CompositeFieldSetSerdeError::InvalidFields)
));
Trait Implementations§
source§impl Clone for CompositeFieldSetSerde
impl Clone for CompositeFieldSetSerde
source§fn clone(&self) -> CompositeFieldSetSerde
fn clone(&self) -> CompositeFieldSetSerde
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for CompositeFieldSetSerde
impl Debug for CompositeFieldSetSerde
source§impl<'de> Deserialize<'de> for CompositeFieldSetSerde
impl<'de> Deserialize<'de> for CompositeFieldSetSerde
source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<CompositeFieldSetSerde, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<CompositeFieldSetSerde, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl From<CompositeFieldSet> for CompositeFieldSetSerde
impl From<CompositeFieldSet> for CompositeFieldSetSerde
source§fn from(value: CompositeFieldSet) -> CompositeFieldSetSerde
fn from(value: CompositeFieldSet) -> CompositeFieldSetSerde
Converts to this type from the input type.
source§impl PartialEq for CompositeFieldSetSerde
impl PartialEq for CompositeFieldSetSerde
source§impl Serialize for CompositeFieldSetSerde
impl Serialize for CompositeFieldSetSerde
source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
source§impl TryFrom<CompositeFieldSetSerde> for CompositeFieldSet
impl TryFrom<CompositeFieldSetSerde> for CompositeFieldSet
source§type Error = CompositeFieldSetSerdeError
type Error = CompositeFieldSetSerdeError
The type returned in the event of a conversion error.
source§fn try_from(
value: CompositeFieldSetSerde,
) -> Result<CompositeFieldSet, <CompositeFieldSet as TryFrom<CompositeFieldSetSerde>>::Error>
fn try_from( value: CompositeFieldSetSerde, ) -> Result<CompositeFieldSet, <CompositeFieldSet as TryFrom<CompositeFieldSetSerde>>::Error>
Performs the conversion.
impl Copy for CompositeFieldSetSerde
impl StructuralPartialEq for CompositeFieldSetSerde
Auto Trait Implementations§
impl Freeze for CompositeFieldSetSerde
impl RefUnwindSafe for CompositeFieldSetSerde
impl Send for CompositeFieldSetSerde
impl Sync for CompositeFieldSetSerde
impl Unpin for CompositeFieldSetSerde
impl UnwindSafe for CompositeFieldSetSerde
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more