Skip to content

Commit 0c04208

Browse files
committed
add features to top-level crate
1 parent 913c0d6 commit 0c04208

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

crates/cuid/Cargo.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ homepage.workspace = true
1111
repository.workspace = true
1212

1313
[dependencies]
14-
cuid1.workspace = true
15-
cuid2.workspace = true
14+
cuid1 = { workspace = true, optional = true }
15+
cuid2 = { workspace = true, optional = true }
1616

1717
[lib]
1818
name = "cuid"
@@ -21,3 +21,8 @@ path = "src/lib.rs"
2121
[[bin]]
2222
name = "cuid"
2323
path = "src/bin.rs"
24+
25+
[features]
26+
default = ["v1", "v2"]
27+
v1 = ["dep:cuid1"]
28+
v2 = ["dep:cuid2"]

crates/cuid/src/lib.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
//!
2525
//! ```sh
2626
//! $> cuid --v2
27+
//! i12sf8k69lbvktlr7qb4p6xv
2728
//! ```
2829
//!
2930
//! See the [original v1 implementation] and [original v2 implementation] for
@@ -33,10 +34,15 @@
3334
//! [original v2 implementation]: https://github.com/paralleldrive/cuid2
3435
//!
3536
36-
pub use cuid1::{cuid as cuid1, is_cuid as is_cuid1, is_slug as is_cuid1_slug, slug as cuid1_slug};
37+
#[cfg(feature = "v1")]
38+
pub use cuid1::{
39+
cuid as cuid1, is_cuid as is_cuid1, is_slug as is_cuid1_slug, slug as cuid1_slug,
40+
};
41+
#[cfg(feature = "v1")]
3742
#[doc(hidden)]
3843
pub use cuid1::{one_off_cuid1, one_off_cuid1_slug};
3944

45+
#[cfg(feature = "v2")]
4046
pub use cuid2::{
4147
cuid as cuid2, is_cuid2, is_slug as is_cuid2_slug, slug as cuid2_slug,
4248
CuidConstructor as Cuid2Constructor,

0 commit comments

Comments
 (0)