-
-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using serde_with::rust::sets_last_value_wins with serde_as notation #534
Comments
Hi, thanks for raising the issue. That is indeed currently not possible, as this module and the related ones were never updated. I don't think there is any technical challenge here, just a bit of busy work. If you need this urgently, you can also create a conversion type in your codebase. You can follow the guide and replace |
I am interested in implementing this, but what would the syntax look like in the |
You need a new type and implement the traits for it (see link). pub struct SetLastValueWins<V>(PhantomData<V>); You should then be able to use it like any other #[serde_as(as = "SetLastValueWins<_>")]
BTreeSet<u32>, |
pub(crate) struct SetLastValueWins<T>(PhantomData<T>);
impl<T, U> SerializeAs<IndexSet<T>> for SetLastValueWins<U>
where
T: Eq + Hash + Serialize,
{
fn serialize_as<S>(value: &IndexSet<T>, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
sets_last_value_wins::serialize(value, serializer)
}
}
impl<'de, T, U> DeserializeAs<'de, IndexSet<T>> for SetLastValueWins<U>
where
T: Eq + Hash + Deserialize<'de>,
{
fn deserialize_as<D>(deserializer: D) -> Result<IndexSet<T>, D::Error>
where
D: Deserializer<'de>,
{
sets_last_value_wins::deserialize(deserializer)
}
} With my implementation above, it seems like it does not use the |
In this case, you will need to adapt the existing code a bit. The values need to be transformed, since you cannot directly serialize a |
563: Add serde_as compatible versions for duplicate key handling r=jonasbb a=jonasbb This adds `serde_as` compatible versions for these four modules: `maps_duplicate_key_is_error`, `maps_first_key_wins`, `sets_duplicate_value_is_error`, and `sets_last_value_wins`. Missing: - [x] Documentation Closes #534 Co-authored-by: Jonas Bushart <[email protected]>
I would like to use
serde_with::rust::sets_last_value_wins
with theserde_as
notation, but that does not seem to be possible. Am I missing something?The text was updated successfully, but these errors were encountered: