Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 56 additions & 40 deletions src/external/serde_support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,40 +360,44 @@ pub mod compact {
}
}

/// Serialize from a [`Uuid`] as a `uuid::fmt::Simple`
/// Serialize a [`Uuid`] as [`uuid::fmt::Simple`].
///
/// [`Uuid`]: ../../struct.Uuid.html
///
/// ## Example
/// ## Examples
///
/// ```rust
/// Serialize and deserialize using the simple format, failing to deserialize
/// any other format:
///
/// ```
/// #[derive(serde_derive::Serialize, serde_derive::Deserialize)]
/// struct StructA {
/// // This will change both serialization and deserialization
/// #[serde(with = "uuid::serde::simple")]
/// id: uuid::Uuid,
/// }
/// ```
///
/// Serialize using the simple format, but deserialize any format:
///
/// ```
/// #[derive(serde_derive::Serialize, serde_derive::Deserialize)]
/// struct StructB {
/// // This will be serialized as uuid::fmt::Simple and deserialize from all valid formats
/// #[serde(serialize_with = "uuid::serde::simple::serialize")]
/// id: uuid::Uuid,
/// }
/// ```
pub mod simple {
use super::*;

/// Serialize from a [`Uuid`] as a `uuid::fmt::Simple`
/// Serialize a [`Uuid`] as a simple string.
///
/// [`Uuid`]: ../../struct.Uuid.html
///
/// # Example
/// # Examples
///
/// ```rust
/// ```
/// #[derive(serde_derive::Serialize)]
/// struct Struct {
/// // This will be serialize as uuid::fmt::Simple
/// #[serde(serialize_with = "uuid::serde::simple::serialize")]
/// id: uuid::Uuid,
/// }
Expand All @@ -406,7 +410,7 @@ pub mod simple {
serde_core::Serialize::serialize(u.as_simple(), serializer)
}

/// Deserialize a simple Uuid string as a [`Uuid`]
/// Deserialize a simple-formatted string as a [`Uuid`].
///
/// [`Uuid`]: ../../struct.Uuid.html
pub fn deserialize<'de, D>(deserializer: D) -> Result<Uuid, D::Error>
Expand Down Expand Up @@ -478,40 +482,44 @@ pub mod simple {
}
}

/// Serialize from a [`Uuid`] as a `uuid::fmt::Braced`
/// Serialize a [`Uuid`] as [`uuid::fmt::Braced`].
///
/// [`Uuid`]: ../../struct.Uuid.html
///
/// ## Example
/// ## Examples
///
/// ```rust
/// Serialize and deserialize using the braced format, failing to deserialize
/// any other format:
///
/// ```
/// #[derive(serde_derive::Serialize, serde_derive::Deserialize)]
/// struct StructA {
/// // This will change both serialization and deserialization
/// #[serde(with = "uuid::serde::braced")]
/// id: uuid::Uuid,
/// }
/// ```
///
/// Serialize using the braced format, but deserialize any format:
///
/// ```
/// #[derive(serde_derive::Serialize, serde_derive::Deserialize)]
/// struct StructB {
/// // This will be serialized as uuid::fmt::Braced and deserialize from all valid formats
/// #[serde(serialize_with = "uuid::serde::braced::serialize")]
/// id: uuid::Uuid,
/// }
/// ```
pub mod braced {
use super::*;

/// Serialize from a [`Uuid`] as a `uuid::fmt::Braced`
/// Serialize a [`Uuid`] as a braced string.
///
/// [`Uuid`]: ../../struct.Uuid.html
///
/// # Example
/// # Examples
///
/// ```rust
/// ```
/// #[derive(serde_derive::Serialize)]
/// struct Struct {
/// // This will be serialize as uuid::fmt::Braced
/// #[serde(serialize_with = "uuid::serde::braced::serialize")]
/// id: uuid::Uuid,
/// }
Expand All @@ -524,7 +532,7 @@ pub mod braced {
serde_core::Serialize::serialize(u.as_braced(), serializer)
}

/// Deserialize a braced Uuid string as a [`Uuid`]
/// Deserialize a braced-formatted string as a [`Uuid`].
///
/// [`Uuid`]: ../../struct.Uuid.html
pub fn deserialize<'de, D>(deserializer: D) -> Result<crate::Uuid, D::Error>
Expand Down Expand Up @@ -597,23 +605,28 @@ pub mod braced {
}
}

/// Serialize from a [`Uuid`] as a `uuid::fmt::Hyphenated`
/// Serialize a [`Uuid`] as [`uuid::fmt::Hyphenated`].
///
/// [`Uuid`]: ../../struct.Uuid.html
///
/// ## Example
/// ## Examples
///
/// ```rust
/// Serialize and deserialize using the hyphenated format, failing to deserialize
/// any other format:
///
/// ```
/// #[derive(serde_derive::Serialize, serde_derive::Deserialize)]
/// struct StructA {
/// // This will change both serialization and deserialization
/// #[serde(with = "uuid::serde::hyphenated")]
/// id: uuid::Uuid,
/// }
/// ```
///
/// Serialize using the hyphenated format, but deserialize any format:
///
/// ```
/// #[derive(serde_derive::Serialize, serde_derive::Deserialize)]
/// struct StructB {
/// // This will be serialized as uuid::fmt::Hyphenated and deserialize from all valid formats
/// #[serde(serialize_with = "uuid::serde::hyphenated::serialize")]
/// id: uuid::Uuid,
/// }
Expand All @@ -622,16 +635,15 @@ pub mod hyphenated {

use super::*;

/// Serialize from a [`Uuid`] as a `uuid::fmt::Hyphenated`
/// Serialize a [`Uuid`] as a hyphenated string.
///
/// [`Uuid`]: ../../struct.Uuid.html
///
/// # Example
/// # Examples
///
/// ```rust
/// ```
/// #[derive(serde_derive::Serialize)]
/// struct Struct {
/// // This will be serialized as uuid::fmt::Hyphenated
/// #[serde(serialize_with = "uuid::serde::hyphenated::serialize")]
/// id: uuid::Uuid,
/// }
Expand All @@ -644,7 +656,7 @@ pub mod hyphenated {
serde_core::Serialize::serialize(u.as_hyphenated(), serializer)
}

/// Deserialize a hyphenated Uuid string as a [`Uuid`]
/// Deserialize a hyphenated-formatted string as a [`Uuid`].
///
/// [`Uuid`]: ../../struct.Uuid.html
pub fn deserialize<'de, D>(deserializer: D) -> Result<crate::Uuid, D::Error>
Expand Down Expand Up @@ -717,40 +729,44 @@ pub mod hyphenated {
}
}

/// Serialize from a [`Uuid`] as a `uuid::fmt::Urn`
/// Serialize a [`Uuid`] as [`uuid::fmt::Urn`].
///
/// [`Uuid`]: ../../struct.Uuid.html
///
/// ## Example
/// ## Examples
///
/// ```rust
/// Serialize and deserialize using the URN format, failing to deserialize
/// any other format:
///
/// ```
/// #[derive(serde_derive::Serialize, serde_derive::Deserialize)]
/// struct StructA {
/// // This will change both serialization and deserialization
/// #[serde(with = "uuid::serde::urn")]
/// id: uuid::Uuid,
/// }
/// ```
///
/// Serialize using the URN format, but deserialize any format:
///
/// ```
/// #[derive(serde_derive::Serialize, serde_derive::Deserialize)]
/// struct StructB {
/// // This will be serialized as uuid::fmt::Urn and deserialize from all valid formats
/// #[serde(serialize_with = "uuid::serde::urn::serialize")]
/// id: uuid::Uuid,
/// }
/// ```
pub mod urn {
use super::*;

/// Serialize from a [`Uuid`] as a `uuid::fmt::Urn`
/// Serialize a [`Uuid`] as a URN string.
///
/// [`Uuid`]: ../../struct.Uuid.html
///
/// # Example
/// # Examples
///
/// ```rust
/// ```
/// #[derive(serde_derive::Serialize)]
/// struct Struct {
/// // This will be serialize as uuid::fmt::Urn
/// #[serde(serialize_with = "uuid::serde::urn::serialize")]
/// id: uuid::Uuid,
/// }
Expand All @@ -763,7 +779,7 @@ pub mod urn {
serde_core::Serialize::serialize(u.as_urn(), serializer)
}

/// Deserialize a urn Uuid string as a [`Uuid`]
/// Deserialize a URN-formatted string as a [`Uuid`].
///
/// [`Uuid`]: ../../struct.Uuid.html
pub fn deserialize<'de, D>(deserializer: D) -> Result<crate::Uuid, D::Error>
Expand Down
4 changes: 2 additions & 2 deletions src/external/slog_support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ impl slog::Value for NonNilUuid {

#[cfg(test)]
mod tests {
use crate::tests::new;
use crate::tests::some_uuid_v4;

use slog::{crit, Drain};

#[test]
fn test_slog_kv() {
let root = slog::Logger::root(slog::Discard.fuse(), slog::o!());
let u1 = new();
let u1 = some_uuid_v4();
crit!(root, "test"; "u1" => u1);
}
}
Loading
Loading