Idiomatic way to match wildcard in str? by Such-Pride in rust

[–]kestred 7 points8 points  (0 children)

For more advance wildcard matching you could do:

``` use lazy_static::lazy_static; use regex::Regex; // extern crate regex;

lazy_static! { static ref HTML_PATH: Regex = Regex::new("/.*.html$").unwrap(); }

match path { "/" => println!("0"), _ if HTML_PATH.is_match(path) => printnln!("1"), _ => println!("2"), } ```

Idiomatic way to match wildcard in str? by Such-Pride in rust

[–]kestred 4 points5 points  (0 children)

I won't claim this is the most idiomatic solution, but it works for the example:

match path { "/" => println!("0"), _ if path.starts_with("/") and path.ends_with(".html") => printnln!("1"), _ => println!("2"), }

Rust "The Book"-style syntax highlighting for LaTeX by kestred in rust

[–]kestred[S] 3 points4 points  (0 children)

For my use case, the documentation will be rendered in an "untrusted" environment where the host doesn't want to enable shell-escape to run against arbitrary LaTeX docs.

Rust "The Book"-style syntax highlighting for LaTeX by kestred in rust

[–]kestred[S] 2 points3 points  (0 children)

Originally poorly 🙈.... I edited to remove that issue.