Created
September 18, 2019 04:56
-
-
Save krisselden/c4e2825a9eff449ffe926dfb79809345 to your computer and use it in GitHub Desktop.
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
#[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