identifiers: Add as_bytes to all types with as_str
This commit is contained in:
parent
2e5fceb2b5
commit
82b7cc1637
@ -42,6 +42,11 @@ impl DeviceId {
|
|||||||
pub fn as_str(&self) -> &str {
|
pub fn as_str(&self) -> &str {
|
||||||
&self.0
|
&self.0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Creates a byte slice from this `DeviceId`.
|
||||||
|
pub fn as_bytes(&self) -> &[u8] {
|
||||||
|
self.0.as_bytes()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Clone for Box<DeviceId> {
|
impl Clone for Box<DeviceId> {
|
||||||
|
@ -33,6 +33,13 @@ macro_rules! common_impls {
|
|||||||
&self.full_id
|
&self.full_id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
doc_concat! {
|
||||||
|
#[doc = concat!("Creates a byte slice from this `", stringify!($id), "`")]
|
||||||
|
pub fn as_bytes(&self) -> &[u8] {
|
||||||
|
self.full_id.as_bytes()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ::std::convert::AsRef<str> for $id {
|
impl ::std::convert::AsRef<str> for $id {
|
||||||
|
@ -86,7 +86,7 @@ impl RoomVersionId {
|
|||||||
Self::Version6
|
Self::Version6
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a string slice from this `RoomVersionId`
|
/// Creates a string slice from this `RoomVersionId`.
|
||||||
pub fn as_str(&self) -> &str {
|
pub fn as_str(&self) -> &str {
|
||||||
match &self {
|
match &self {
|
||||||
Self::Version1 => "1",
|
Self::Version1 => "1",
|
||||||
@ -99,6 +99,11 @@ impl RoomVersionId {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Creates a byte slice from this `RoomVersionId`.
|
||||||
|
pub fn as_bytes(&self) -> &[u8] {
|
||||||
|
self.as_str().as_bytes()
|
||||||
|
}
|
||||||
|
|
||||||
/// Whether or not this room version is an official one specified by the Matrix protocol.
|
/// Whether or not this room version is an official one specified by the Matrix protocol.
|
||||||
pub fn is_official(&self) -> bool {
|
pub fn is_official(&self) -> bool {
|
||||||
!self.is_custom()
|
!self.is_custom()
|
||||||
|
@ -32,6 +32,11 @@ impl ServerName {
|
|||||||
pub fn as_str(&self) -> &str {
|
pub fn as_str(&self) -> &str {
|
||||||
&self.0
|
&self.0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Creates a byte slice from this `ServerName`.
|
||||||
|
pub fn as_bytes(&self) -> &[u8] {
|
||||||
|
self.0.as_bytes()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Clone for Box<ServerName> {
|
impl Clone for Box<ServerName> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user