Enum sea_orm_rocket::figment::value::magic::Either [−]
pub enum Either<A, B> {
Left(A),
Right(B),
}Expand description
(De)serializes as either a magic value A or any other deserializable value
B.
An Either<A, B> deserializes as either an A or B, whichever succeeds
first.
The usual Either implementation or an “untagged” enum does not allow its
internal values to provide hints to the deserializer. These hints are
required for magic values to work. By contrast, this Either does provide
the appropriate hints.
Example
use serde::{Serialize, Deserialize};
use figment::{Figment, value::magic::{Either, RelativePathBuf, Tagged}};
#[derive(Debug, PartialEq, Deserialize, Serialize)]
struct Config {
int_or_str: Either<Tagged<usize>, String>,
path_or_bytes: Either<RelativePathBuf, Vec<u8>>,
}
fn figment<A: Serialize, B: Serialize>(a: A, b: B) -> Figment {
Figment::from(("int_or_str", a)).merge(("path_or_bytes", b))
}
let config: Config = figment(10, "/a/b").extract().unwrap();
assert_eq!(config.int_or_str, Either::Left(10.into()));
assert_eq!(config.path_or_bytes, Either::Left("/a/b".into()));
let config: Config = figment("hi", "c/d").extract().unwrap();
assert_eq!(config.int_or_str, Either::Right("hi".into()));
assert_eq!(config.path_or_bytes, Either::Left("c/d".into()));
let config: Config = figment(123, &[1, 2, 3]).extract().unwrap();
assert_eq!(config.int_or_str, Either::Left(123.into()));
assert_eq!(config.path_or_bytes, Either::Right(vec![1, 2, 3].into()));
let config: Config = figment("boo!", &[4, 5, 6]).extract().unwrap();
assert_eq!(config.int_or_str, Either::Right("boo!".into()));
assert_eq!(config.path_or_bytes, Either::Right(vec![4, 5, 6].into()));
let config: Config = Figment::from(figment::providers::Serialized::defaults(Config {
int_or_str: Either::Left(10.into()),
path_or_bytes: Either::Left("a/b/c".into()),
})).extract().unwrap();
assert_eq!(config.int_or_str, Either::Left(10.into()));
assert_eq!(config.path_or_bytes, Either::Left("a/b/c".into()));
let config: Config = Figment::from(figment::providers::Serialized::defaults(Config {
int_or_str: Either::Right("hi".into()),
path_or_bytes: Either::Right(vec![3, 7, 13]),
})).extract().unwrap();
assert_eq!(config.int_or_str, Either::Right("hi".into()));
assert_eq!(config.path_or_bytes, Either::Right(vec![3, 7, 13]));Variants
Left(A)
The “left” variant.
Right(B)
The “right” variant.
Trait Implementations
impl<'de, 'b, A, B> Deserialize<'de> for Either<A, B> where
'de: 'b,
A: Magic,
B: Deserialize<'b>,
impl<'de, 'b, A, B> Deserialize<'de> for Either<A, B> where
'de: 'b,
A: Magic,
B: Deserialize<'b>,
pub fn deserialize<D>(
de: D
) -> Result<Either<A, B>, <D as Deserializer<'de>>::Error> where
D: Deserializer<'de>,
pub fn deserialize<D>(
de: D
) -> Result<Either<A, B>, <D as Deserializer<'de>>::Error> where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl<A, B> PartialOrd<Either<A, B>> for Either<A, B> where
A: PartialOrd<A>,
B: PartialOrd<B>,
impl<A, B> PartialOrd<Either<A, B>> for Either<A, B> where
A: PartialOrd<A>,
B: PartialOrd<B>,
pub fn partial_cmp(&self, other: &Either<A, B>) -> Option<Ordering>
pub fn partial_cmp(&self, other: &Either<A, B>) -> Option<Ordering>
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <=
operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
pub fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error> where
__S: Serializer,
pub 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
impl<A, B> StructuralEq for Either<A, B>
impl<A, B> StructuralPartialEq for Either<A, B>
Auto Trait Implementations
impl<A, B> RefUnwindSafe for Either<A, B> where
A: RefUnwindSafe,
B: RefUnwindSafe,
impl<A, B> UnwindSafe for Either<A, B> where
A: UnwindSafe,
B: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
Compare self to key and return true if they are equal.
pub fn into_collection<A>(self) -> SmallVec<A> where
A: Array<Item = T>,
pub fn into_collection<A>(self) -> SmallVec<A> where
A: Array<Item = T>,
Converts self into a collection.
pub fn vzip(self) -> V
Attaches the provided Subscriber to this type, returning a
WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a
WithDispatch wrapper. Read more
