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§

source

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);
source

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%
}
source

fn to_path(&self) -> Box<Path>

str String to Path

source

fn to_pathbuf(&self) -> PathBuf

str String to PathBuf

source

fn parse_to_surf_header(&self) -> Result<HeaderInfo, Box<dyn Error>>

Implementors§

source§

impl<S: AsRef<str>> Str for S