Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created July 11, 2019 20:48
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 rust-play/e1116c8f214be1e482adc792c4222db3 to your computer and use it in GitHub Desktop.
Save rust-play/e1116c8f214be1e482adc792c4222db3 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
#![allow(unused)]
use std::borrow::Cow;
use std::borrow::ToOwned;
fn main() {
let s = "sdfsf".to_string();
let cow: Cow<str> = Cow::Owned(s);
// not own
let s2: String = cow.as_ref().into();
let s4 = Into::<String>::into(cow.as_ref());
//println!("{}", &cow);
// own
//let s3 = cow.into_owned();
// cause error
// println!("{}", &cow);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment