Skip to content

Instantly share code, notes, and snippets.

@harryscholes
Created November 5, 2021 09:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harryscholes/137d2ae850ade2e9e2f59f86a6873a3d to your computer and use it in GitHub Desktop.
Save harryscholes/137d2ae850ade2e9e2f59f86a6873a3d to your computer and use it in GitHub Desktop.
Rust: how to clone a type that is not Clone
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