Add DeviceId
.
This commit is contained in:
parent
9011423eea
commit
b37bb53495
24
src/device_id.rs
Normal file
24
src/device_id.rs
Normal file
@ -0,0 +1,24 @@
|
||||
//! Matrix device identifiers.
|
||||
|
||||
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.
|
||||
pub fn generate() -> DeviceId {
|
||||
generate_localpart(8).to_string()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::generate;
|
||||
|
||||
#[test]
|
||||
fn generate_device_id() {
|
||||
assert_eq!(generate().len(), 8);
|
||||
}
|
||||
}
|
@ -38,11 +38,14 @@ use url::Url;
|
||||
|
||||
pub use url::Host;
|
||||
|
||||
#[doc(inline)]
|
||||
pub use crate::device_id::DeviceId;
|
||||
pub use crate::{
|
||||
error::Error, event_id::EventId, room_alias_id::RoomAliasId, room_id::RoomId,
|
||||
room_id_or_room_alias_id::RoomIdOrAliasId, room_version_id::RoomVersionId, user_id::UserId,
|
||||
};
|
||||
|
||||
pub mod device_id;
|
||||
#[cfg(feature = "diesel")]
|
||||
mod diesel_integration;
|
||||
mod error;
|
||||
|
Loading…
x
Reference in New Issue
Block a user