pub struct Flatten<T, U>(pub T, pub U);Expand description
Helper for flattening deserialisation, compatible with serde_ignored
A combination of two structs T and U.
The serde representation flattens both structs into a single, larger, struct.
Furthermore, unlike plain use of #[serde(flatten)],
serde_ignored will still detect fields which appear in serde input
but which form part of neither T nor U.
T and U must both be Flattenable.
Usually that trait should be derived with
the Flattenable macro.
If it’s desired to combine more than two structs, Flatten can be nested.
§Limitations
Field name overlaps are not detected.
Fields which appear in both structs
will be processed as part of T during deserialization.
They will be internally presented as duplicate fields during serialization,
with the outcome depending on the data format implementation.
§Example
use serde::{Serialize, Deserialize};
use derive_deftly::Deftly;
use tor_config::{Flatten, derive_deftly_template_Flattenable};
#[derive(Serialize, Deserialize, Debug, Deftly, Eq, PartialEq)]
#[derive_deftly(Flattenable)]
struct A {
a: i32,
}
#[derive(Serialize, Deserialize, Debug, Deftly, Eq, PartialEq)]
#[derive_deftly(Flattenable)]
struct B {
b: String,
}
let combined: Flatten<A,B> = toml::from_str(r#"
a = 42
b = "hello"
"#).unwrap();
assert_eq!(
combined,
Flatten(A { a: 42 }, B { b: "hello".into() }),
);Tuple Fields§
§0: T§1: UTrait Implementations§
Source§impl<'de, T, U> Deserialize<'de> for Flatten<T, U>
impl<'de, T, U> Deserialize<'de> for Flatten<T, U>
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>,
Source§impl<T, U> Flattenable for Flatten<T, U>where
T: Flattenable,
U: Flattenable,
Flatten may be nested
impl<T, U> Flattenable for Flatten<T, U>where
T: Flattenable,
U: Flattenable,
Flatten may be nested
Source§impl<T: Ord, U: Ord> Ord for Flatten<T, U>
impl<T: Ord, U: Ord> Ord for Flatten<T, U>
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<T: PartialOrd, U: PartialOrd> PartialOrd for Flatten<T, U>
impl<T: PartialOrd, U: PartialOrd> PartialOrd for Flatten<T, U>
impl<T: Copy, U: Copy> Copy for Flatten<T, U>
impl<T: Eq, U: Eq> Eq for Flatten<T, U>
impl<T, U> StructuralPartialEq for Flatten<T, U>
Auto Trait Implementations§
impl<T, U> Freeze for Flatten<T, U>
impl<T, U> RefUnwindSafe for Flatten<T, U>where
T: RefUnwindSafe,
U: RefUnwindSafe,
impl<T, U> Send for Flatten<T, U>
impl<T, U> Sync for Flatten<T, U>
impl<T, U> Unpin for Flatten<T, U>
impl<T, U> UnwindSafe for Flatten<T, U>where
T: UnwindSafe,
U: UnwindSafe,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
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>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
Source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
Source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
impl<T> ErasedDestructor for Twhere
T: 'static,
Layout§
Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.