Trait newtype_uuid::TypedUuidKind

source ·
pub trait TypedUuidKind:
    Send
    + Sync
    + 'static {
    // Required method
    fn tag() -> TypedUuidTag;
}
Expand description

Represents marker types that can be used as a type parameter for TypedUuid.

Generally, an implementation of this will be a zero-sized type that can never be constructed. An empty struct or enum works well for this.

§Implementations

If the schemars08 feature is enabled, and JsonSchema is implemented for a kind T, then TypedUuid<T> will also implement JsonSchema.

§Notes

If you have a large number of UUID kinds, it can be repetitive to implement this trait for each kind. Here’s a template for a macro that can help:

use newtype_uuid::{TypedUuidKind, TypedUuidTag};

macro_rules! impl_typed_uuid_kind {
    ($($kind:ident => $tag:literal),* $(,)?) => {
        $(
            pub enum $kind {}

            impl TypedUuidKind for $kind {
                #[inline]
                fn tag() -> TypedUuidTag {
                    const TAG: TypedUuidTag = TypedUuidTag::new($tag);
                    TAG
                }
            }
        )*
    };
}

// Invoke this macro with:
impl_typed_uuid_kind! {
    Kind1 => "kind1",
    Kind2 => "kind2",
}

Required Methods§

source

fn tag() -> TypedUuidTag

Returns the corresponding tag for this kind.

The tag forms a runtime representation of this type.

The tag is required to be a static string.

Object Safety§

This trait is not object safe.

Implementors§