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-27.0.0 ./ext/cargo-vendor/maybe-owned-0.3.4/src/serde_impls.rs
wasmtime-26.0.0 ./ext/cargo-vendor/maybe-owned-0.3.4/src/serde_impls.rs
wasmtime-25.0.2 ./ext/cargo-vendor/maybe-owned-0.3.4/src/serde_impls.rs
wasmtime-25.0.1 ./ext/cargo-vendor/maybe-owned-0.3.4/src/serde_impls.rs
wasmtime-25.0.0 ./ext/cargo-vendor/maybe-owned-0.3.4/src/serde_impls.rs
wasmtime-24.0.0 ./ext/cargo-vendor/maybe-owned-0.3.4/src/serde_impls.rs
wasmtime-23.0.2 ./ext/cargo-vendor/maybe-owned-0.3.4/src/serde_impls.rs
wasmtime-22.0.0 ./ext/cargo-vendor/maybe-owned-0.3.4/src/serde_impls.rs
wasmtime-21.0.1 ./ext/cargo-vendor/maybe-owned-0.3.4/src/serde_impls.rs
wasmtime-20.0.2 ./ext/cargo-vendor/maybe-owned-0.3.4/src/serde_impls.rs
wasmtime-20.0.0 ./ext/cargo-vendor/maybe-owned-0.3.4/src/serde_impls.rs
wasmtime-18.0.3 ./ext/cargo-vendor/maybe-owned-0.3.4/src/serde_impls.rs
wasmtime-17.0.1 ./ext/cargo-vendor/maybe-owned-0.3.4/src/serde_impls.rs
wasmtime-17.0.0 ./ext/cargo-vendor/maybe-owned-0.3.4/src/serde_impls.rs
wasmtime-16.0.0 ./ext/cargo-vendor/maybe-owned-0.3.4/src/serde_impls.rs
wasmtime-15.0.1 ./ext/cargo-vendor/maybe-owned-0.3.4/src/serde_impls.rs
wasmtime-15.0.0 ./ext/cargo-vendor/maybe-owned-0.3.4/src/serde_impls.rs
wasmtime-14.0.4 ./ext/cargo-vendor/maybe-owned-0.3.4/src/serde_impls.rs
wasmtime-14.0.3 ./ext/cargo-vendor/maybe-owned-0.3.4/src/serde_impls.rs
wasmtime-14.0.1 ./ext/cargo-vendor/maybe-owned-0.3.4/src/serde_impls.rs