mirror of
https://github.com/napi-rs/napi-rs.git
synced 2025-12-08 19:56:07 +00:00
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:
parent
282ce1c00a
commit
164ef2a9f3
@ -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) ),+
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user