add clone to SendSafe* types

This commit is contained in:
Brendan Hansknecht 2022-10-19 11:54:17 -07:00
parent 24cd78fe7e
commit 6ebfcc8fa1
No known key found for this signature in database
GPG key ID: 0EA784685083E75B
2 changed files with 25 additions and 0 deletions

View file

@ -619,6 +619,20 @@ pub struct SendSafeRocList<T>(RocList<T>);
unsafe impl<T> Send for SendSafeRocList<T> where T: Send {}
impl<T> Clone for SendSafeRocList<T>
where
T: Clone,
{
fn clone(&self) -> Self {
if self.0.is_readonly() {
SendSafeRocList(self.0.clone())
} else {
// To keep self send safe, this must copy.
SendSafeRocList(RocList::from_slice(&self.0))
}
}
}
impl<T> From<RocList<T>> for SendSafeRocList<T>
where
T: Clone,

View file

@ -657,6 +657,17 @@ pub struct SendSafeRocStr(RocStr);
unsafe impl Send for SendSafeRocStr {}
impl Clone for SendSafeRocStr {
fn clone(&self) -> Self {
if self.0.is_readonly() {
SendSafeRocStr(self.0.clone())
} else {
// To keep self send safe, this must copy.
SendSafeRocStr(RocStr::from(self.0.as_str()))
}
}
}
impl From<RocStr> for SendSafeRocStr {
fn from(s: RocStr) -> Self {
if s.is_unique() || s.is_readonly() {