ruma_identifiers/
transaction_id.rs

1/// A Matrix transaction ID.
2///
3/// Transaction IDs in Matrix are opaque strings. This type is provided simply for its semantic
4/// value.
5///
6/// You can create one from a string (using `.into()`) but the recommended way is to use
7/// `TransactionId::new()` to generate a random one. If that function is not available for you, you
8/// need to activate this crate's `rand` Cargo feature.
9#[repr(transparent)]
10#[derive(PartialEq, Eq, PartialOrd, Ord, Hash)]
11pub struct TransactionId(str);
12
13impl TransactionId {
14    /// Creates a random transaction ID.
15    ///
16    /// This will currently be a UUID without hyphens, but no guarantees are made about the
17    /// structure of transaction IDs generated from this function.
18    #[cfg(feature = "rand")]
19    pub fn new() -> Box<Self> {
20        let id = uuid::Uuid::new_v4();
21        Self::from_owned(id.to_simple().to_string().into_boxed_str())
22    }
23}
24
25opaque_identifier!(TransactionId);