Struct query_string_builder::QueryString
source · pub struct QueryString<'a> { /* private fields */ }
Expand description
A query string builder for percent encoding key-value pairs.
Example
use query_string_builder::QueryString;
let qs = QueryString::new()
.with_value("q", "apple")
.with_value("category", "fruits and vegetables");
assert_eq!(
format!("https://example.com/{qs}"),
"https://example.com/?q=apple&category=fruits%20and%20vegetables"
);
Implementations§
source§impl<'a> QueryString<'a>
impl<'a> QueryString<'a>
sourcepub fn with_value(self, key: &'a str, value: &'a str) -> Self
pub fn with_value(self, key: &'a str, value: &'a str) -> Self
Appends a key-value pair to the query string.
Example
use query_string_builder::QueryString;
let qs = QueryString::new()
.with_value("q", "🍎 apple")
.with_value("category", "fruits and vegetables");
assert_eq!(
format!("https://example.com/{qs}"),
"https://example.com/?q=%F0%9F%8D%8E%20apple&category=fruits%20and%20vegetables"
);
sourcepub fn with_opt_value(self, key: &'a str, value: Option<&'a str>) -> Self
pub fn with_opt_value(self, key: &'a str, value: Option<&'a str>) -> Self
Appends a key-value pair to the query string if the value exists.
Example
use query_string_builder::QueryString;
let qs = QueryString::new()
.with_opt_value("q", Some("🍎 apple"))
.with_opt_value("f", None)
.with_opt_value("category", Some("fruits and vegetables"));
assert_eq!(
format!("https://example.com/{qs}"),
"https://example.com/?q=%F0%9F%8D%8E%20apple&category=fruits%20and%20vegetables"
);
sourcepub fn push(&mut self, key: &'a str, value: &'a str) -> &Self
pub fn push(&mut self, key: &'a str, value: &'a str) -> &Self
Appends a key-value pair to the query string.
Example
use query_string_builder::QueryString;
let mut qs = QueryString::new();
qs.push("q", "apple");
qs.push("category", "fruits and vegetables");
assert_eq!(
format!("https://example.com/{qs}"),
"https://example.com/?q=apple&category=fruits%20and%20vegetables"
);
sourcepub fn push_opt(&mut self, key: &'a str, value: Option<&'a str>) -> &Self
pub fn push_opt(&mut self, key: &'a str, value: Option<&'a str>) -> &Self
Appends a key-value pair to the query string if the value exists.
Example
use query_string_builder::QueryString;
let mut qs = QueryString::new();
qs.push_opt("q", None);
qs.push_opt("q", Some("🍎 apple"));
assert_eq!(
format!("https://example.com/{qs}"),
"https://example.com/?q=%F0%9F%8D%8E%20apple"
);
sourcepub fn append(&mut self, other: QueryString<'a>)
pub fn append(&mut self, other: QueryString<'a>)
Appends another query string builder’s values.
Example
use query_string_builder::QueryString;
let mut qs = QueryString::new().with_value("q", "apple");
let more = QueryString::new().with_value("q", "pear");
qs.append(more);
assert_eq!(
format!("https://example.com/{qs}"),
"https://example.com/?q=apple&q=pear"
);
sourcepub fn append_into(self, other: QueryString<'a>) -> Self
pub fn append_into(self, other: QueryString<'a>) -> Self
Appends another query string builder’s values, consuming both types.
Example
use query_string_builder::QueryString;
let qs = QueryString::new().with_value("q", "apple");
let more = QueryString::new().with_value("q", "pear");
let qs = qs.append_into(more);
assert_eq!(
format!("https://example.com/{qs}"),
"https://example.com/?q=apple&q=pear"
);
Trait Implementations§
source§impl<'a> Clone for QueryString<'a>
impl<'a> Clone for QueryString<'a>
source§fn clone(&self) -> QueryString<'a>
fn clone(&self) -> QueryString<'a>
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl<'a> Debug for QueryString<'a>
impl<'a> Debug for QueryString<'a>
source§impl<'a> Default for QueryString<'a>
impl<'a> Default for QueryString<'a>
source§fn default() -> QueryString<'a>
fn default() -> QueryString<'a>
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl<'a> RefUnwindSafe for QueryString<'a>
impl<'a> Send for QueryString<'a>
impl<'a> Sync for QueryString<'a>
impl<'a> Unpin for QueryString<'a>
impl<'a> UnwindSafe for QueryString<'a>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more