Struct query_string_builder::QueryString
source · pub struct QueryString { /* 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 QueryString
impl QueryString
sourcepub fn with_value<K: Into<String>, V: Into<String>>(
self,
key: K,
value: V
) -> Self
pub fn with_value<K: Into<String>, V: Into<String>>( self, key: K, value: V ) -> 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<K: Into<String>, V: Into<String>>(
self,
key: K,
value: Option<V>
) -> Self
pub fn with_opt_value<K: Into<String>, V: Into<String>>( self, key: K, value: Option<V> ) -> 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::<String>)
.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<K: Into<String>, V: Into<String>>(
&mut self,
key: K,
value: V
) -> &Self
pub fn push<K: Into<String>, V: Into<String>>( &mut self, key: K, value: V ) -> &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<K: Into<String>, V: Into<String>>(
&mut self,
key: K,
value: Option<V>
) -> &Self
pub fn push_opt<K: Into<String>, V: Into<String>>( &mut self, key: K, value: Option<V> ) -> &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::<String>);
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)
pub fn append(&mut self, other: QueryString)
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) -> Self
pub fn append_into(self, other: QueryString) -> 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 Clone for QueryString
impl Clone for QueryString
source§fn clone(&self) -> QueryString
fn clone(&self) -> QueryString
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 Debug for QueryString
impl Debug for QueryString
source§impl Default for QueryString
impl Default for QueryString
source§fn default() -> QueryString
fn default() -> QueryString
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl RefUnwindSafe for QueryString
impl Send for QueryString
impl Sync for QueryString
impl Unpin for QueryString
impl UnwindSafe for QueryString
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