Implement debug for identifier types
This commit is contained in:
parent
4831585223
commit
68ba3049ea
@ -14,6 +14,7 @@ Improvements:
|
|||||||
|
|
||||||
* Add `DeviceKeyId::from_parts` and `SigningKeyId::from_parts`
|
* Add `DeviceKeyId::from_parts` and `SigningKeyId::from_parts`
|
||||||
* Add `DeviceIdBox` and `ServerNameBox` type aliases
|
* Add `DeviceIdBox` and `ServerNameBox` type aliases
|
||||||
|
* Clean up debug logs for identifiers
|
||||||
|
|
||||||
# 0.17.4
|
# 0.17.4
|
||||||
|
|
||||||
|
@ -1,16 +1,22 @@
|
|||||||
//! Identifiers for device keys for end-to-end encryption.
|
//! Identifiers for device keys for end-to-end encryption.
|
||||||
|
|
||||||
use std::{convert::TryInto, num::NonZeroU8};
|
use std::{convert::TryInto, fmt, num::NonZeroU8};
|
||||||
|
|
||||||
use crate::{crypto_algorithms::DeviceKeyAlgorithm, DeviceId, Error};
|
use crate::{crypto_algorithms::DeviceKeyAlgorithm, DeviceId, Error};
|
||||||
|
|
||||||
/// A key algorithm and a device id, combined with a ':'
|
/// A key algorithm and a device id, combined with a ':'
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone)]
|
||||||
pub struct DeviceKeyId {
|
pub struct DeviceKeyId {
|
||||||
full_id: Box<str>,
|
full_id: Box<str>,
|
||||||
colon_idx: NonZeroU8,
|
colon_idx: NonZeroU8,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Debug for DeviceKeyId {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
f.write_str(&self.full_id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl DeviceKeyId {
|
impl DeviceKeyId {
|
||||||
/// Create a `DeviceKeyId` from a `DeviceKeyAlgorithm` and a `DeviceId`.
|
/// Create a `DeviceKeyId` from a `DeviceKeyAlgorithm` and a `DeviceId`.
|
||||||
pub fn from_parts(algorithm: DeviceKeyAlgorithm, device_id: &DeviceId) -> Self {
|
pub fn from_parts(algorithm: DeviceKeyAlgorithm, device_id: &DeviceId) -> Self {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//! Matrix event identifiers.
|
//! Matrix event identifiers.
|
||||||
|
|
||||||
use std::{convert::TryFrom, num::NonZeroU8};
|
use std::{convert::TryFrom, fmt, num::NonZeroU8};
|
||||||
|
|
||||||
use crate::{Error, ServerName};
|
use crate::{Error, ServerName};
|
||||||
|
|
||||||
@ -37,12 +37,18 @@ use crate::{Error, ServerName};
|
|||||||
/// "$Rqnc-F-dvnEYJTyHq_iKxU2bZ1CI92-kuZq3a5lr5Zg"
|
/// "$Rqnc-F-dvnEYJTyHq_iKxU2bZ1CI92-kuZq3a5lr5Zg"
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone)]
|
||||||
pub struct EventId {
|
pub struct EventId {
|
||||||
full_id: Box<str>,
|
full_id: Box<str>,
|
||||||
colon_idx: Option<NonZeroU8>,
|
colon_idx: Option<NonZeroU8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Debug for EventId {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
f.write_str(&self.full_id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl EventId {
|
impl EventId {
|
||||||
/// Attempts to generate an `EventId` for the given origin server with a localpart consisting
|
/// Attempts to generate an `EventId` for the given origin server with a localpart consisting
|
||||||
/// of 18 random ASCII characters. This should only be used for events in the original format
|
/// of 18 random ASCII characters. This should only be used for events in the original format
|
||||||
|
@ -146,7 +146,6 @@ macro_rules! opaque_identifier {
|
|||||||
) => {
|
) => {
|
||||||
$( #[doc = $docs] )*
|
$( #[doc = $docs] )*
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
#[derive(::std::fmt::Debug)]
|
|
||||||
pub struct $id(str);
|
pub struct $id(str);
|
||||||
|
|
||||||
::paste::paste! {
|
::paste::paste! {
|
||||||
@ -185,6 +184,12 @@ macro_rules! opaque_identifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ::std::fmt::Debug for $id {
|
||||||
|
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
|
||||||
|
f.write_str(self.as_ref())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Clone for ::std::boxed::Box<$id> {
|
impl Clone for ::std::boxed::Box<$id> {
|
||||||
fn clone(&self) -> Self {
|
fn clone(&self) -> Self {
|
||||||
(**self).to_owned()
|
(**self).to_owned()
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//! Matrix room alias identifiers.
|
//! Matrix room alias identifiers.
|
||||||
|
|
||||||
use std::{convert::TryFrom, num::NonZeroU8};
|
use std::{convert::TryFrom, fmt, num::NonZeroU8};
|
||||||
|
|
||||||
use crate::{server_name::ServerName, Error};
|
use crate::{server_name::ServerName, Error};
|
||||||
|
|
||||||
@ -17,12 +17,18 @@ use crate::{server_name::ServerName, Error};
|
|||||||
/// "#ruma:example.com"
|
/// "#ruma:example.com"
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone)]
|
||||||
pub struct RoomAliasId {
|
pub struct RoomAliasId {
|
||||||
pub(crate) full_id: Box<str>,
|
pub(crate) full_id: Box<str>,
|
||||||
pub(crate) colon_idx: NonZeroU8,
|
pub(crate) colon_idx: NonZeroU8,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Debug for RoomAliasId {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
f.write_str(&self.full_id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl RoomAliasId {
|
impl RoomAliasId {
|
||||||
/// Returns the room's alias.
|
/// Returns the room's alias.
|
||||||
pub fn alias(&self) -> &str {
|
pub fn alias(&self) -> &str {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//! Matrix room identifiers.
|
//! Matrix room identifiers.
|
||||||
|
|
||||||
use std::{convert::TryFrom, num::NonZeroU8};
|
use std::{convert::TryFrom, fmt, num::NonZeroU8};
|
||||||
|
|
||||||
use crate::{Error, ServerName};
|
use crate::{Error, ServerName};
|
||||||
|
|
||||||
@ -17,12 +17,18 @@ use crate::{Error, ServerName};
|
|||||||
/// "!n8f893n9:example.com"
|
/// "!n8f893n9:example.com"
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone)]
|
||||||
pub struct RoomId {
|
pub struct RoomId {
|
||||||
pub(crate) full_id: Box<str>,
|
pub(crate) full_id: Box<str>,
|
||||||
pub(crate) colon_idx: NonZeroU8,
|
pub(crate) colon_idx: NonZeroU8,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Debug for RoomId {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
f.write_str(&self.full_id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl RoomId {
|
impl RoomId {
|
||||||
/// Attempts to generate a `RoomId` for the given origin server with a localpart consisting of
|
/// Attempts to generate a `RoomId` for the given origin server with a localpart consisting of
|
||||||
/// 18 random ASCII characters.
|
/// 18 random ASCII characters.
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//! Matrix identifiers for places where a room ID or room alias ID are used interchangeably.
|
//! Matrix identifiers for places where a room ID or room alias ID are used interchangeably.
|
||||||
|
|
||||||
use std::{convert::TryFrom, hint::unreachable_unchecked, num::NonZeroU8};
|
use std::{convert::TryFrom, fmt, hint::unreachable_unchecked, num::NonZeroU8};
|
||||||
|
|
||||||
use crate::{server_name::ServerName, Error, RoomAliasId, RoomId};
|
use crate::{server_name::ServerName, Error, RoomAliasId, RoomId};
|
||||||
|
|
||||||
@ -23,12 +23,18 @@ use crate::{server_name::ServerName, Error, RoomAliasId, RoomId};
|
|||||||
/// "!n8f893n9:example.com"
|
/// "!n8f893n9:example.com"
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone)]
|
||||||
pub struct RoomIdOrAliasId {
|
pub struct RoomIdOrAliasId {
|
||||||
full_id: Box<str>,
|
full_id: Box<str>,
|
||||||
colon_idx: NonZeroU8,
|
colon_idx: NonZeroU8,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Debug for RoomIdOrAliasId {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
f.write_str(&self.full_id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl RoomIdOrAliasId {
|
impl RoomIdOrAliasId {
|
||||||
/// Returns the local part (everything after the `!` or `#` and before the first colon).
|
/// Returns the local part (everything after the `!` or `#` and before the first colon).
|
||||||
pub fn localpart(&self) -> &str {
|
pub fn localpart(&self) -> &str {
|
||||||
|
@ -13,7 +13,7 @@ use crate::Error;
|
|||||||
|
|
||||||
/// A Matrix-spec compliant server name.
|
/// A Matrix-spec compliant server name.
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(transparent, crate = "serde"))]
|
#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(transparent, crate = "serde"))]
|
||||||
pub struct ServerName(str);
|
pub struct ServerName(str);
|
||||||
|
|
||||||
@ -45,6 +45,12 @@ impl ServerName {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Debug for ServerName {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
f.write_str(self.as_str())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Clone for Box<ServerName> {
|
impl Clone for Box<ServerName> {
|
||||||
fn clone(&self) -> Self {
|
fn clone(&self) -> Self {
|
||||||
(**self).to_owned()
|
(**self).to_owned()
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//! Matrix user identifiers.
|
//! Matrix user identifiers.
|
||||||
|
|
||||||
use std::{convert::TryFrom, num::NonZeroU8};
|
use std::{convert::TryFrom, fmt, num::NonZeroU8};
|
||||||
|
|
||||||
use crate::{Error, ServerName};
|
use crate::{Error, ServerName};
|
||||||
|
|
||||||
@ -17,7 +17,7 @@ use crate::{Error, ServerName};
|
|||||||
/// "@carl:example.com"
|
/// "@carl:example.com"
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone)]
|
||||||
pub struct UserId {
|
pub struct UserId {
|
||||||
full_id: Box<str>,
|
full_id: Box<str>,
|
||||||
colon_idx: NonZeroU8,
|
colon_idx: NonZeroU8,
|
||||||
@ -30,6 +30,12 @@ pub struct UserId {
|
|||||||
is_historical: bool,
|
is_historical: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Debug for UserId {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
f.write_str(&self.full_id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl UserId {
|
impl UserId {
|
||||||
/// Attempts to generate a `UserId` for the given origin server with a localpart consisting of
|
/// Attempts to generate a `UserId` for the given origin server with a localpart consisting of
|
||||||
/// 12 random ASCII characters.
|
/// 12 random ASCII characters.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user