identifiers: Fix up Rc / Arc conversions
This commit is contained in:
parent
5d0803f63d
commit
e5c93ab928
@ -1,5 +1,9 @@
|
||||
# [unreleased]
|
||||
|
||||
Improvement:
|
||||
|
||||
* Add conversions of borrowed `ServerName`, `DeviceId` and `KeyName` to `Arc<_>` and `Rc<_>`
|
||||
|
||||
# 0.19.2
|
||||
|
||||
Improvements:
|
||||
|
@ -63,6 +63,20 @@ impl From<&ServerName> for Box<ServerName> {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&ServerName> for Rc<ServerName> {
|
||||
fn from(s: &ServerName) -> Self {
|
||||
let rc = Rc::<str>::from(s.as_str());
|
||||
unsafe { Rc::from_raw(Rc::into_raw(rc) as *const ServerName) }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&ServerName> for Arc<ServerName> {
|
||||
fn from(s: &ServerName) -> Self {
|
||||
let arc = Arc::<str>::from(s.as_str());
|
||||
unsafe { Arc::from_raw(Arc::into_raw(arc) as *const ServerName) }
|
||||
}
|
||||
}
|
||||
|
||||
fn try_from<S>(server_name: S) -> Result<Box<ServerName>, crate::Error>
|
||||
where
|
||||
S: AsRef<str> + Into<Box<str>>,
|
||||
@ -114,26 +128,6 @@ 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> {
|
||||
type Error = crate::Error;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user