Answers for "rust string to &str"

0

string and str to string rust

pub trait Literal {
    fn literal(&self) -> String;
}

// Using the .literal() method on a String or &str returns the String.

impl Literal for String { fn literal(&self) -> String { return self.clone() } }
impl Literal for &str { fn literal(&self) -> String { return String::from(*self); } }
Posted by: Guest on February-19-2022
0

rust string to &str

let s: String = "abcdefg".to_owned();
let s_slice: &str = &s[..];  // take a full slice of the string
Posted by: Guest on March-03-2022

Browse Popular Code Answers by Language