Skip to main content

sigid_flexible/
lib.rs

1// SPDX-License-Identifier: MIT OR Apache-2.0
2
3//! # SigID Flexible
4//!
5//! Configurable ID generator with custom:
6//! - Length (12-64 characters)
7//! - Alphabet (Crockford32, Base64, custom)
8//! - Prefixes (compile-time or runtime)
9//! - Checksum (optional)
10//!
11//! # Example
12//! ```
13//! use sigid_flexible::{Generator, Alphabet};
14//!
15//! let mut gen = Generator::new()
16//!     .length(24)
17//!     .alphabet(Alphabet::Crockford32)
18//!     .build();
19//!
20//! let id = gen.generate(1234567890).unwrap();
21//! println!("{}", id);
22//! ```
23
24#![cfg_attr(not(feature = "std"), no_std)]
25#![warn(missing_docs, missing_debug_implementations)]
26
27extern crate alloc;
28
29mod alphabet;
30mod checksum;
31mod generator;
32
33pub use alphabet::Alphabet;
34pub use checksum::{add_checksum, verify_checksum};
35pub use generator::Generator;
36
37/// Re-export core types
38pub use sigid_core::{Error, Result, SigId26, COUNTER_MAX, EPOCH};
39
40#[cfg(feature = "std")]
41pub mod prefix {
42    //! Prefix handling (std only)
43    use std::string::String;
44
45    /// Runtime prefix
46    #[derive(Debug, Clone, PartialEq, Eq)]
47    pub struct RuntimePrefix {
48        inner: String,
49    }
50
51    impl RuntimePrefix {
52        /// Create new runtime prefix
53        pub fn new(s: impl Into<String>) -> Self {
54            Self { inner: s.into() }
55        }
56
57        /// Get prefix string
58        pub fn as_str(&self) -> &str {
59            &self.inner
60        }
61
62        /// Get prefix length
63        pub fn len(&self) -> usize {
64            self.inner.len()
65        }
66
67        /// Check if prefix is empty
68        pub fn is_empty(&self) -> bool {
69            self.inner.is_empty()
70        }
71    }
72
73    impl core::fmt::Display for RuntimePrefix {
74        fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
75            f.write_str(&self.inner)
76        }
77    }
78}