Trait surf_header::utils::Str
source · pub trait Str {
// Required methods
fn cut(&self, start: i32, end: i32, step: usize) -> String;
fn format(
&self,
targets: Vec<(Box<dyn ToString>, Box<dyn ToString>)>
) -> String;
fn to_path(&self) -> Box<Path>;
fn to_pathbuf(&self) -> PathBuf;
fn parse_to_surf_header(&self) -> Result<HeaderInfo, Box<dyn Error>>;
}Required Methods§
sourcefn cut(&self, start: i32, end: i32, step: usize) -> String
fn cut(&self, start: i32, end: i32, step: usize) -> String
implment cut format for str and String
use surf_header::Str;
let a = "this is a demo {}";
let c = a.cut(-1,-2,1);
let f = a.format("so {}").format(vec![("{}","demo")]);
println!("{:?}",f);
println!("{:?}",c);sourcefn format(&self, targets: Vec<(Box<dyn ToString>, Box<dyn ToString>)>) -> String
fn format(&self, targets: Vec<(Box<dyn ToString>, Box<dyn ToString>)>) -> String
implment format for impl ToString
fn main() {
use surf_header::Print;
use surf_header::Str;
"this is a {s},I like Trait Object {p}%"
.format(vec![(Box::new("{s}"),Box::new("demo")),(Box::new("{p}"),Box::new(100))]).println();//this is a demo,I like Trait Object 100%
use surf_header::targets;
"this is a {d},I like Trait Object {p}}%"
.format(targets!{"{d}"=>"demo","{p}"=>100})
.println(); //this is a demo,I like Trait Object 100%
}sourcefn to_pathbuf(&self) -> PathBuf
fn to_pathbuf(&self) -> PathBuf
str String to PathBuf