You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
692 B
32 lines
692 B
//! IDs used for data objects and models.
|
|
//!
|
|
//! UUID is always unique; the numeric ID used as a fallback
|
|
//! is auto-incrementing, but some values may be skipped.
|
|
//!
|
|
//! It is better to treat both ID implementations as opaque.
|
|
|
|
#[cfg(feature = "uuid-ids")]
|
|
#[allow(non_camel_case_types)]
|
|
pub type ID = uuid::Uuid;
|
|
|
|
#[cfg(not(feature = "uuid-ids"))]
|
|
#[allow(non_camel_case_types)]
|
|
pub type ID = u32;
|
|
|
|
/// Something that has ID
|
|
pub trait HaveId {
|
|
fn get_id(&self) -> ID;
|
|
}
|
|
|
|
#[cfg(feature = "uuid-ids")]
|
|
#[cfg(test)]
|
|
pub fn random_id() -> ID {
|
|
ID::new_v4()
|
|
}
|
|
|
|
#[cfg(not(feature = "uuid-ids"))]
|
|
#[cfg(test)]
|
|
pub fn random_id() -> ID {
|
|
use rand::Rng;
|
|
rand::thread_rng().gen()
|
|
}
|
|
|