mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 05:49:08 +00:00
add clone to SendSafe* types
This commit is contained in:
parent
24cd78fe7e
commit
6ebfcc8fa1
2 changed files with 25 additions and 0 deletions
|
@ -619,6 +619,20 @@ pub struct SendSafeRocList<T>(RocList<T>);
|
||||||
|
|
||||||
unsafe impl<T> Send for SendSafeRocList<T> where T: Send {}
|
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>
|
impl<T> From<RocList<T>> for SendSafeRocList<T>
|
||||||
where
|
where
|
||||||
T: Clone,
|
T: Clone,
|
||||||
|
|
|
@ -657,6 +657,17 @@ pub struct SendSafeRocStr(RocStr);
|
||||||
|
|
||||||
unsafe impl Send for SendSafeRocStr {}
|
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 {
|
impl From<RocStr> for SendSafeRocStr {
|
||||||
fn from(s: RocStr) -> Self {
|
fn from(s: RocStr) -> Self {
|
||||||
if s.is_unique() || s.is_readonly() {
|
if s.is_unique() || s.is_readonly() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue