Skip to content

Commit c2c81c2

Browse files
committed
address review comments
Created using spr 1.3.6-beta.1
1 parent 592b938 commit c2c81c2

File tree

3 files changed

+39
-43
lines changed

3 files changed

+39
-43
lines changed

crates/newtype-uuid-macros/src/internals/imp.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,6 @@ fn generate_schemars_impl(
409409
use ::#newtype_uuid_crate::macro_support::schemars08::schema::*;
410410

411411
let mut schema = SchemaObject {
412-
instance_type: ::std::option::Option::None,
413412
subschemas: ::std::option::Option::Some(Box::new(SubschemaValidation {
414413
not: ::std::option::Option::Some(Box::new(Schema::Bool(true))),
415414
..::std::default::Default::default()

crates/newtype-uuid-macros/src/lib.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ use quote::ToTokens;
5656
///
5757
/// By default, for a kind `Foo`, this macro generates:
5858
///
59-
/// * A `FooKind` type that implements `TypedUuidKind`: `pub type FooKind {}`.
59+
/// * A `FooKind` type that implements `TypedUuidKind`: `pub enum FooKind {}`.
6060
/// * A `FooUuid` type alias: `pub type FooUuid = TypedUuid<FooKind>;`.
6161
///
6262
/// ## Examples
@@ -68,26 +68,27 @@ use quote::ToTokens;
6868
/// impl_typed_uuid_kinds! {
6969
/// kinds = {
7070
/// User = {},
71-
/// Organization = {},
71+
/// BusinessUnit = {},
7272
/// },
7373
/// }
7474
///
75-
/// // This generates empty UserKind and OrganizationKind enums implementing
76-
/// // TypedUuidKind, with the tags "user" and "organization" respectively.
75+
/// // This generates empty UserKind and BusinessUnitKind enums implementing
76+
/// // TypedUuidKind, with the tags "user" and "business_unit" respectively.
7777
/// // Tags are snake_case versions of type names.
7878
/// assert_eq!(UserKind::tag().as_str(), "user");
79-
/// assert_eq!(OrganizationKind::tag().as_str(), "organization");
79+
/// assert_eq!(BusinessUnitKind::tag().as_str(), "business_unit");
8080
///
81-
/// // The macro also generates UserUuid and OrganizationUuid type aliases.
81+
/// // The macro also generates UserUuid and BusinessUnitUuid type aliases.
8282
/// let user_uuid = UserUuid::new_v4();
83-
/// let organization_uuid = OrganizationUuid::new_v4();
83+
/// let business_unit_uuid = BusinessUnitUuid::new_v4();
8484
/// ```
8585
///
8686
/// * The generated `Kind` types always implement `Clone`, `Copy`, `Debug`,
8787
/// `Eq`, and `PartialEq`.
88-
/// * The `Kind` types are all empty (uninhabited) enums, which means that
89-
/// values for these types cannot be created. (Using empty enums is the
90-
/// recommended approach for `newtype-uuid`).
88+
/// * The `Kind` types are all empty enums, also known as *marker* or
89+
/// *uninhabited* enums. This means that values for these types cannot be
90+
/// created. (Using empty enums is the recommended approach for
91+
/// `newtype-uuid`).
9192
///
9293
/// # Per-kind settings
9394
///
@@ -154,14 +155,15 @@ use quote::ToTokens;
154155
/// If the `schemars08` global setting is defined, the macro generates JSON
155156
/// Schema support for the `Kind` instances using [schemars 0.8].
156157
///
157-
/// **To enable JSON Schema support, you'll need to turn on `newtype-uuid`'s
158+
/// **To enable JSON Schema support, you'll need to enable `newtype-uuid`'s
158159
/// `schemars08` feature.**
159160
///
160161
/// Within `settings.schemars08`, the options are:
161162
///
162163
/// - `attrs`: A list of attributes to apply to all generated `JsonSchema`
163-
/// implementations. This will often be something like `[#cfg(feature =
164-
/// "schemars-feature-name")]]`.
164+
/// implementations. For example, if `schemars` is an optional dependency
165+
/// for the crate where the macro is being invoked, you might specify something
166+
/// like `[#cfg(feature = "schemars")]`.
165167
/// - `rust_type`: If defined, adds the `x-rust-type` extension to the schema,
166168
/// enabling automatic replacement with [`typify`] and other tools that
167169
/// support it. *Optional, defaults to not adding the extension.*
@@ -201,7 +203,7 @@ use quote::ToTokens;
201203
/// attrs = [#[cfg(feature = "schemars")]],
202204
/// rust_type = {
203205
/// crate = "my-crate",
204-
/// version = "*",
206+
/// version = "0.1.0",
205207
/// path = "my_crate::types",
206208
/// },
207209
/// },

crates/newtype-uuid/src/lib.rs

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
//! ```
4242
//!
4343
//! If you have a large number of UUID kinds, consider using
44-
//! [`newtype-uuid-macros`] which comes with several convenience features:
44+
//! [`newtype-uuid-macros`] which comes with several convenience features.
4545
//!
4646
//! ```
4747
//! use newtype_uuid_macros::impl_typed_uuid_kinds;
@@ -151,6 +151,7 @@ extern crate alloc;
151151
/// This module re-exports types needed for [`newtype-uuid-macros`] to work.
152152
///
153153
/// [`newtype-uuid-macros`]: https://docs.rs/newtype-uuid-macros
154+
#[doc(hidden)]
154155
pub mod macro_support {
155156
#[cfg(feature = "schemars08")]
156157
pub use schemars as schemars08;
@@ -664,37 +665,25 @@ mod proptest1_imp {
664665
/// If the `schemars08` feature is enabled, and [`JsonSchema`] is implemented for a kind `T`, then
665666
/// [`TypedUuid`]`<T>` will also implement [`JsonSchema`].
666667
///
667-
/// # Notes
668-
///
669-
/// If you have a large number of UUID kinds, it can be repetitive to implement this trait for each
670-
/// kind. Here's a template for a macro that can help:
668+
/// If you have a large number of UUID kinds, consider using
669+
/// [`newtype-uuid-macros`] which comes with several convenience features.
671670
///
672671
/// ```
673-
/// use newtype_uuid::{TypedUuidKind, TypedUuidTag};
674-
///
675-
/// macro_rules! impl_typed_uuid_kind {
676-
/// ($($kind:ident => $tag:literal),* $(,)?) => {
677-
/// $(
678-
/// pub enum $kind {}
679-
///
680-
/// impl TypedUuidKind for $kind {
681-
/// #[inline]
682-
/// fn tag() -> TypedUuidTag {
683-
/// const TAG: TypedUuidTag = TypedUuidTag::new($tag);
684-
/// TAG
685-
/// }
686-
/// }
687-
/// )*
688-
/// };
689-
/// }
672+
/// use newtype_uuid_macros::impl_typed_uuid_kinds;
690673
///
691674
/// // Invoke this macro with:
692-
/// impl_typed_uuid_kind! {
693-
/// Kind1 => "kind1",
694-
/// Kind2 => "kind2",
675+
/// impl_typed_uuid_kinds! {
676+
/// kinds = {
677+
/// User = {},
678+
/// Project = {},
679+
/// // ...
680+
/// },
695681
/// }
696682
/// ```
697683
///
684+
/// See [`newtype-uuid-macros`] for more information.
685+
///
686+
/// [`newtype-uuid-macros`]: https://docs.rs/newtype-uuid-macros
698687
/// [`JsonSchema`]: schemars::JsonSchema
699688
pub trait TypedUuidKind: Send + Sync + 'static {
700689
/// Returns the corresponding tag for this kind.
@@ -704,10 +693,16 @@ pub trait TypedUuidKind: Send + Sync + 'static {
704693
/// The tag is required to be a static string.
705694
fn tag() -> TypedUuidTag;
706695

707-
/// Returns an alias for `TypedUuid<Self>`, if one is defined.
696+
/// Returns a string that corresponds to a type alias for `TypedUuid<Self>`,
697+
/// if one is defined.
698+
///
699+
/// The type alias must be defined in the same module as `Self`. This
700+
/// function is used by the schemars integration to refer to embed a
701+
/// reference to that alias in the schema, if available.
702+
///
703+
/// This is usually defined by the [`newtype-uuid-macros`] crate.
708704
///
709-
/// The alias must be defined in the same module as `Self`. This alias is
710-
/// used by schemars integration to refer to `TypedUuid<Self>` if available.
705+
/// [`newtype-uuid-macros`]: https://docs.rs/newtype-uuid-macros
711706
#[inline]
712707
fn alias() -> Option<&'static str> {
713708
None

0 commit comments

Comments
 (0)