chore: implement serde::Serialize for Either (#2209)

This adds an implementation of serde::Serialize for all the Either types.
Long term, we might want to use the either crate, but for now this makes this
implementation usable with serde.
This commit is contained in:
Louis 2024-08-05 13:05:49 +03:00 committed by GitHub
parent 282ce1c00a
commit 164ef2a9f3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -150,6 +150,18 @@ macro_rules! either_n {
}
}
}
#[cfg(feature = "serde-json")]
impl< $( $parameter: serde::Serialize ),+ > serde::Serialize for $either_name< $( $parameter ),+ > {
fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
where
Ser: serde::Serializer
{
match &self {
$( Self:: $parameter (v) => serializer.serialize_some(v) ),+
}
}
}
};
}