1 unstable release
Uses old Rust 2015
0.1.0 | Jul 2, 2017 |
---|
#22 in #chars
21 downloads per month
Used in macos-open
7KB
141 lines
Fast escape
Simple, fast escaping of characters.
This crate builds on fast_fmt
to provide flexibility and speed.
lib.rs
:
This crate provides generic escaping of characters without requiring allocations. It leverages
fast_fmt
crate to do this.
#Examples
Escaping whole writer
#[macro_use]
extern crate fast_fmt;
extern crate fast_escape;
extern crate void;
use fast_escape::Escaper;
use fast_fmt::Write;
use void::ResultVoidExt;
fn main() {
let mut s = String::new();
{
let s = &mut s;
let mut tr = s.transform(Escaper::new('\\', '$'));
fwrite!(&mut tr, "abcd$efgh").void_unwrap();
}
assert_eq!(s, "abcd\\$efgh");
}
Escaping part of formatted text
#[macro_use]
extern crate fast_fmt;
extern crate fast_escape;
extern crate void;
use fast_escape::Escaper;
use void::ResultVoidExt;
fn main() {
let mut s = String::new();
let special_chars = ['$', '"'];
let escaper: Escaper<&[char]> = Escaper::new('\\', &special_chars);
let value = "$Hello \"world\"!";
fwrite!(&mut s, "$foo=\"", value.transformed(escaper), "\"").void_unwrap();
assert_eq!(s, "$foo=\"\\$Hello \\\"world\\\"!\"");
}
Dependencies
~49KB