Created
November 5, 2021 09:44
-
-
Save harryscholes/137d2ae850ade2e9e2f59f86a6873a3d to your computer and use it in GitHub Desktop.
Rust: how to clone a type that is not Clone
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::sync::Arc; | |
struct Foo(); | |
fn main() { | |
let x = Foo(); | |
// x.clone(); // `Foo` is not `Clone` | |
let x = Arc::new(x); // Wrap in `Arc` | |
x.clone(); // Works because `Arc` is `Clone` | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment