identifiers: Add Arc, Rc conversions to ServerName, DeviceId and KeyName
This commit is contained in:
parent
ddc2138141
commit
8f6a7aeedc
@ -236,6 +236,20 @@ macro_rules! opaque_identifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<&$id> for std::rc::Rc<$id> {
|
||||||
|
fn from(s: &$id) -> std::rc::Rc<$id> {
|
||||||
|
let rc = std::rc::Rc::<str>::from(s.as_str());
|
||||||
|
unsafe { std::rc::Rc::from_raw(std::rc::Rc::into_raw(rc) as *const $id) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<&$id> for std::sync::Arc<$id> {
|
||||||
|
fn from(s: &$id) -> std::sync::Arc<$id> {
|
||||||
|
let arc = std::sync::Arc::<str>::from(s.as_str());
|
||||||
|
unsafe { std::sync::Arc::from_raw(std::sync::Arc::into_raw(arc) as *const $id) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a> From<&'a str> for &'a $id {
|
impl<'a> From<&'a str> for &'a $id {
|
||||||
fn from(s: &'a str) -> Self {
|
fn from(s: &'a str) -> Self {
|
||||||
$id::from_borrowed(s)
|
$id::from_borrowed(s)
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
//! Matrix-spec compliant server names.
|
//! Matrix-spec compliant server names.
|
||||||
|
use std::{convert::TryFrom, fmt, mem, rc::Rc, str::FromStr, sync::Arc};
|
||||||
use std::{convert::TryFrom, fmt, mem, str::FromStr};
|
|
||||||
|
|
||||||
use ruma_identifiers_validation::server_name::validate;
|
use ruma_identifiers_validation::server_name::validate;
|
||||||
|
|
||||||
@ -115,6 +114,26 @@ impl TryFrom<&str> for Box<ServerName> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl TryFrom<&ServerName> for Rc<ServerName> {
|
||||||
|
type Error = crate::Error;
|
||||||
|
|
||||||
|
fn try_from(s: &ServerName) -> Result<Self, Self::Error> {
|
||||||
|
validate(s.as_str())?;
|
||||||
|
let rc = Rc::<str>::from(s.as_str());
|
||||||
|
Ok(unsafe { Rc::from_raw(Rc::into_raw(rc) as *const ServerName) })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TryFrom<&ServerName> for Arc<ServerName> {
|
||||||
|
type Error = crate::Error;
|
||||||
|
|
||||||
|
fn try_from(s: &ServerName) -> Result<Self, Self::Error> {
|
||||||
|
validate(s.as_str())?;
|
||||||
|
let arc = Arc::<str>::from(s.as_str());
|
||||||
|
Ok(unsafe { Arc::from_raw(Arc::into_raw(arc) as *const ServerName) })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl TryFrom<String> for Box<ServerName> {
|
impl TryFrom<String> for Box<ServerName> {
|
||||||
type Error = crate::Error;
|
type Error = crate::Error;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user