a small relational database with user-editable schema for manual data entry
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.
|
|
|
//! 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")]
|
|
|
|
mod impl_uuid {
|
|
|
|
/// Common identifier type
|
|
|
|
#[allow(non_camel_case_types)]
|
|
|
|
pub type ID = uuid::Uuid;
|
|
|
|
|
|
|
|
pub fn next_id() -> ID {
|
|
|
|
uuid::Uuid::new_v4()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn zero_id() -> ID {
|
|
|
|
uuid::Uuid::nil()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(not(feature = "uuid-ids"))]
|
|
|
|
mod impl_u64 {
|
|
|
|
/// Common identifier type
|
|
|
|
#[allow(non_camel_case_types)]
|
|
|
|
pub type ID = u64;
|
|
|
|
|
|
|
|
lazy_static::lazy_static! {
|
|
|
|
static ref COUNTER: parking_lot::Mutex<u64> = parking_lot::Mutex::new(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn next_id() -> ID {
|
|
|
|
let mut m = COUNTER.lock();
|
|
|
|
let v = *m;
|
|
|
|
*m += 1;
|
|
|
|
v
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn zero_id() -> ID {
|
|
|
|
0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(not(feature = "uuid-ids"))]
|
|
|
|
pub use impl_u64::{next_id, zero_id, ID};
|
|
|
|
#[cfg(feature = "uuid-ids")]
|
|
|
|
pub use impl_uuid::{next_id, zero_id, ID};
|
|
|
|
|
|
|
|
/// Something that has ID
|
|
|
|
pub trait HaveId {
|
|
|
|
fn get_id(&self) -> ID;
|
|
|
|
}
|