Struct fluent_uri::enc::EStr
source · #[repr(transparent)]pub struct EStr { /* private fields */ }
Expand description
Percent-encoded string slices.
Examples
Parse key-value pairs from a query string into a hash map:
use std::collections::HashMap;
use fluent_uri::enc::EStr;
let query = "name=%E5%BC%A0%E4%B8%89&speech=%C2%A1Ol%C3%A9!";
let map: HashMap<_, _> = EStr::new(query)
.split('&')
.filter_map(|pair| pair.split_once('='))
.map(|(k, v)| (k.decode(), v.decode()))
.filter_map(|(k, v)| k.into_string().ok().zip(v.into_string().ok()))
.collect();
assert_eq!(map["name"], "张三");
assert_eq!(map["speech"], "¡Olé!");
Implementations§
source§impl EStr
impl EStr
sourcepub fn decode(&self) -> Decode<'_>
pub fn decode(&self) -> Decode<'_>
Decodes the EStr
.
Examples
use fluent_uri::enc::EStr;
let dec = EStr::new("%C2%BF").decode();
assert_eq!(dec.as_bytes(), &[0xc2, 0xbf]);
assert_eq!(dec.into_string()?, "¿");
sourcepub fn split_once(&self, delim: char) -> Option<(&EStr, &EStr)>
pub fn split_once(&self, delim: char) -> Option<(&EStr, &EStr)>
Splits the EStr
on the first occurrence of the given delimiter and
returns prefix before delimiter and suffix after delimiter.
Returns None
if the delimiter is not found.
Panics
Panics if the delimiter is not a reserved character.
Examples
use fluent_uri::enc::EStr;
let (k, v) = EStr::new("key=value").split_once('=').unwrap();
assert_eq!(k, "key");
assert_eq!(v, "value");
assert!(EStr::new("abc").split_once(';').is_none());
Trait Implementations§
source§impl PartialEq<EStr> for EStr
impl PartialEq<EStr> for EStr
Implements equality comparisons on EStr
s.
EStr
s are compared by their byte values. Percent-encoding
normalization is not performed prior to comparison.