Struct icu_datetime::fieldsets::serde::CompositeFieldSetSerde
source ยท 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::fieldsets;
use icu::datetime::fieldsets::enums::CompositeFieldSet;
use icu::datetime::fieldsets::enums::DateFieldSet;
use icu::datetime::fieldsets::serde::CompositeFieldSetSerde;
let field_set =
CompositeFieldSet::Date(DateFieldSet::YMD(fieldsets::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::fieldsets::enums::CompositeFieldSet;
use icu::datetime::fieldsets::serde::CompositeFieldSetSerde;
use icu::datetime::fieldsets::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<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::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) -> Self
fn from(value: CompositeFieldSet) -> Self
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ยง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.
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