Sha256: fa499e7e94c869dcb6f77d0dcb7b6ea5e8dd1f81ae0026758c4fc16b350a783e

Contents?: true

Size: 947 Bytes

Versions: 36

Compression:

Stored size: 947 Bytes

Contents

//! Serde `Serialize` and `Deserialize` implementations for `MaybeOwned`.
use serde::{Deserialize, Deserializer, Serialize, Serializer};

use {MaybeOwned, MaybeOwnedMut};

macro_rules! serde_impls {
    ($Name:ident) => {
        impl<'a, T: Serialize> Serialize for $Name<'a, T> {
            fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
                match self {
                    Self::Owned(v) => v.serialize(serializer),
                    Self::Borrowed(v) => v.serialize(serializer),
                }
            }
        }

        impl<'a, 'de, T: Deserialize<'de>> Deserialize<'de> for $Name<'a, T> {
            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
            where
                D: Deserializer<'de>,
            {
                T::deserialize(deserializer).map(Self::Owned)
            }
        }
    };
}

serde_impls!(MaybeOwned);
serde_impls!(MaybeOwnedMut);

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
wasmtime-14.0.0 ./ext/cargo-vendor/maybe-owned-0.3.4/src/serde_impls.rs
wasmtime-13.0.0 ./ext/cargo-vendor/maybe-owned-0.3.4/src/serde_impls.rs
wasmtime-12.0.1 ./ext/cargo-vendor/maybe-owned-0.3.4/src/serde_impls.rs
wasmtime-12.0.0 ./ext/cargo-vendor/maybe-owned-0.3.4/src/serde_impls.rs
wasmtime-11.0.0 ./ext/cargo-vendor/maybe-owned-0.3.4/src/serde_impls.rs
wasmtime-10.0.1 ./ext/cargo-vendor/maybe-owned-0.3.4/src/serde_impls.rs
wasmtime-10.0.0 ./ext/cargo-vendor/maybe-owned-0.3.4/src/serde_impls.rs
wasmtime-9.0.4 ./ext/cargo-vendor/maybe-owned-0.3.4/src/serde_impls.rs
wasmtime-9.0.1 ./ext/cargo-vendor/maybe-owned-0.3.4/src/serde_impls.rs
wasmtime-8.0.0 ./ext/cargo-vendor/maybe-owned-0.3.4/src/serde_impls.rs
wasmtime-7.0.0 ./ext/cargo-vendor/maybe-owned-0.3.4/src/serde_impls.rs
wasmtime-6.0.1 ./ext/cargo-vendor/maybe-owned-0.3.4/src/serde_impls.rs
wasmtime-6.0.0 ./ext/cargo-vendor/maybe-owned-0.3.4/src/serde_impls.rs
wasmtime-5.0.0 ./ext/cargo-vendor/maybe-owned-0.3.4/src/serde_impls.rs
wasmtime-0.4.1 ./ext/cargo-vendor/maybe-owned-0.3.4/src/serde_impls.rs
wasmtime-0.4.0 ./ext/cargo-vendor/maybe-owned-0.3.4/src/serde_impls.rs