Skip to content

Instantly share code, notes, and snippets.

@krisselden
Created September 18, 2019 04:56
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 krisselden/c4e2825a9eff449ffe926dfb79809345 to your computer and use it in GitHub Desktop.
Save krisselden/c4e2825a9eff449ffe926dfb79809345 to your computer and use it in GitHub Desktop.
#[derive(Debug, Clone)]
struct SomeTuple<'a>(&'a str, &'a [u8]);
fn main() {
let mut owned = String::new();
owned.push_str("Hello");
owned.push_str(" World");
owned.push('!');
let strref: &str = &owned;
let bytes = owned.as_bytes();
let tuple = SomeTuple(strref, bytes);
println!("{:?}", tuple);
// clone is shallow, does not follow pointers
let cloned = tuple.clone();
println!("{:p} == {:p} == {:p}", strref, tuple.0, cloned.0);
println!("{:p} == {:p} == {:p}", bytes, tuple.1, cloned.1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment