Add DeviceId.

This commit is contained in:
Jimmy Cuadra 2019-06-03 12:13:11 -07:00
parent 9011423eea
commit b37bb53495
2 changed files with 27 additions and 0 deletions

24
src/device_id.rs Normal file
View 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);
}
}

View File

@ -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;