Struct tor_config::Flatten
source · 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_adhoc::Adhoc;
use tor_config::{Flatten, derive_adhoc_template_Flattenable};
#[derive(Serialize, Deserialize, Debug, Adhoc, Eq, PartialEq)]
#[derive_adhoc(Flattenable)]
struct A {
a: i32,
}
#[derive(Serialize, Deserialize, Debug, Adhoc, Eq, PartialEq)]
#[derive_adhoc(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: U
Trait Implementations§
source§impl<'de, T, U> Deserialize<'de> for Flatten<T, U>where
T: Deserialize<'de> + Flattenable,
U: Deserialize<'de> + Flattenable,
impl<'de, T, U> Deserialize<'de> for Flatten<T, U>where T: Deserialize<'de> + Flattenable, U: Deserialize<'de> + Flattenable,
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,
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: PartialEq, U: PartialEq> PartialEq for Flatten<T, U>
impl<T: PartialEq, U: PartialEq> PartialEq for Flatten<T, U>
source§impl<T: PartialOrd, U: PartialOrd> PartialOrd for Flatten<T, U>
impl<T: PartialOrd, U: PartialOrd> PartialOrd for Flatten<T, U>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moreimpl<T: Copy, U: Copy> Copy for Flatten<T, U>
impl<T: Eq, U: Eq> Eq for Flatten<T, U>
impl<T, U> StructuralEq for Flatten<T, U>
impl<T, U> StructuralPartialEq for Flatten<T, U>
Auto Trait Implementations§
impl<T, U> RefUnwindSafe for Flatten<T, U>where T: RefUnwindSafe, U: RefUnwindSafe,
impl<T, U> Send for Flatten<T, U>where T: Send, U: Send,
impl<T, U> Sync for Flatten<T, U>where T: Sync, U: Sync,
impl<T, U> Unpin for Flatten<T, U>where T: Unpin, U: Unpin,
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
§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.