Skip to content

Commit 66d4b6b

Browse files
dodomorandipaolobarbolini
authored andcommitted
feat: add an example of generated code
To show what `typed_uuid` actually generates. It is behind a feature.
1 parent 358bc5b commit 66d4b6b

File tree

4 files changed

+30
-7
lines changed

4 files changed

+30
-7
lines changed

benzina/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,7 @@ mysql = ["benzina-derive?/mysql"]
3030
serde = ["dep:serde", "uuid?/serde"]
3131
utoipa = ["dep:utoipa"]
3232

33+
example-generated = ["typed-uuid"]
34+
3335
[lints]
3436
workspace = true

benzina/src/example_generated.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
use crate::typed_uuid;
2+
3+
typed_uuid!(
4+
/// A example struct generated by [`typed_uuid`].
5+
pub FooId
6+
);

benzina/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ pub use benzina_derive::Enum;
55

66
#[cfg(feature = "postgres")]
77
pub mod error;
8+
#[cfg(feature = "example-generated")]
9+
/// This module shows an example of code generated by the [`typed_uuid`] macro. IT **MUST NOT BE
10+
/// USED OUTSIDE THIS CRATE**.
11+
pub mod example_generated;
812
#[cfg(feature = "postgres")]
913
mod int;
1014
#[cfg(all(feature = "serde", feature = "postgres"))]

benzina/src/typed_uuid.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@
88
/// order to provide the guarantee that the `UUID` is valid. However, it is possible to choose to
99
/// add traits and methods to customize the behavior.
1010
///
11+
#[cfg_attr(
12+
not(feature = "example-generated"),
13+
doc = "To see the documentation of a generated typed `UUID`, consider re-building the \
14+
documentation with the feature `example-generated` enabled."
15+
)]
16+
#[cfg_attr(
17+
feature = "example-generated",
18+
doc = "You can see the documentation for an example generated `UUID` struct \
19+
[`here`](crate::example_generated::FooId)."
20+
)]
21+
///
1122
/// [`Uuid`]: ::uuid::Uuid
1223
///
1324
/// # Examples
@@ -146,12 +157,12 @@ macro_rules! typed_uuid {
146157

147158
$crate::__typed_uuid__forward_from!(
148159
$name:
149-
::uuid::fmt::Braced,
150-
::uuid::fmt::Hyphenated,
151-
::uuid::fmt::Simple,
152-
::uuid::fmt::Urn,
153-
::std::string::String,
154-
::std::vec::Vec<u8>,
160+
::uuid::fmt::Braced,
161+
::uuid::fmt::Hyphenated,
162+
::uuid::fmt::Simple,
163+
::uuid::fmt::Urn,
164+
::std::string::String,
165+
::std::vec::Vec<u8>,
155166
);
156167

157168
impl ::std::fmt::Display for $name {
@@ -173,7 +184,7 @@ macro_rules! typed_uuid {
173184
}
174185

175186
$crate::__typed_uuid__impl_serde!($name);
176-
)+
187+
)+
177188
};
178189
}
179190

0 commit comments

Comments
 (0)