git-subtree-dir: ruma-identifiers git-subtree-mainline: 19ce9645b6651e4de42ddf9e81ee50e19c8c0f26 git-subtree-split: c0a1d8bd440c7cde0fa4ab5e22898ddb26bb706d
28 lines
660 B
Rust
28 lines
660 B
Rust
//! Matrix device identifiers.
|
|
|
|
#[cfg(feature = "rand")]
|
|
use crate::generate_localpart;
|
|
|
|
/// A Matrix device ID.
|
|
///
|
|
/// Device identifiers in Matrix are completely opaque character sequences. This type alias is
|
|
/// provided simply for its semantic value.
|
|
pub type DeviceId = String;
|
|
|
|
/// Generates a random `DeviceId`, suitable for assignment to a new device.
|
|
#[cfg(feature = "rand")]
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "rand")))]
|
|
pub fn generate() -> DeviceId {
|
|
generate_localpart(8)
|
|
}
|
|
|
|
#[cfg(all(test, feature = "rand"))]
|
|
mod tests {
|
|
use super::generate;
|
|
|
|
#[test]
|
|
fn generate_device_id() {
|
|
assert_eq!(generate().len(), 8);
|
|
}
|
|
}
|