pub struct QueryStringOwned { /* private fields */ }Expand description
An owning query string builder for percent encoding key-value pairs.
This is the lifetime-free twin of QueryString: it
eagerly converts keys and values to owned Strings, so it can be stored
in structs, returned from functions and passed around freely.
§Example
use query_string_builder::QueryStringOwned;
let qs = QueryStringOwned::new()
.with("q", "apple")
.with("tasty", true)
.with_opt("category", Some("fruits and vegetables"));
assert_eq!(
format!("https://example.com/{qs}"),
"https://example.com/?q=apple&tasty=true&category=fruits%20and%20vegetables"
);Implementations§
Source§impl QueryStringOwned
impl QueryStringOwned
Sourcepub fn with<K: ToString, V: ToString>(self, key: K, value: V) -> Self
pub fn with<K: ToString, V: ToString>(self, key: K, value: V) -> Self
Appends a key-value pair to the query string.
§Example
use query_string_builder::QueryStringOwned;
let qs = QueryStringOwned::new()
.with("q", "🍎 apple")
.with("category", "fruits and vegetables")
.with("answer", 42);
assert_eq!(
format!("https://example.com/{qs}"),
"https://example.com/?q=%F0%9F%8D%8E%20apple&category=fruits%20and%20vegetables&answer=42"
);Sourcepub fn with_opt<K: ToString, V: ToString>(
self,
key: K,
value: Option<V>,
) -> Self
pub fn with_opt<K: ToString, V: ToString>( 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::QueryStringOwned;
let qs = QueryStringOwned::new()
.with_opt("q", Some("🍎 apple"))
.with_opt("f", None::<String>)
.with_opt("category", Some("fruits and vegetables"))
.with_opt("works", Some(true));
assert_eq!(
format!("https://example.com/{qs}"),
"https://example.com/?q=%F0%9F%8D%8E%20apple&category=fruits%20and%20vegetables&works=true"
);Sourcepub fn push<K: ToString, V: ToString>(&mut self, key: K, value: V) -> &mut Self
pub fn push<K: ToString, V: ToString>(&mut self, key: K, value: V) -> &mut Self
Appends a key-value pair to the query string.
§Example
use query_string_builder::QueryStringOwned;
let mut qs = QueryStringOwned::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: ToString, V: ToString>(
&mut self,
key: K,
value: Option<V>,
) -> &mut Self
pub fn push_opt<K: ToString, V: ToString>( &mut self, key: K, value: Option<V>, ) -> &mut Self
Appends a key-value pair to the query string if the value exists.
§Example
use query_string_builder::QueryStringOwned;
let mut qs = QueryStringOwned::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: QueryStringOwned)
pub fn append(&mut self, other: QueryStringOwned)
Appends another query string builder’s values.
§Example
use query_string_builder::QueryStringOwned;
let mut qs = QueryStringOwned::new().with("q", "apple");
let more = QueryStringOwned::new().with("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: QueryStringOwned) -> Self
pub fn append_into(self, other: QueryStringOwned) -> Self
Appends another query string builder’s values, consuming both types.
§Example
use query_string_builder::QueryStringOwned;
let qs = QueryStringOwned::new().with("q", "apple");
let more = QueryStringOwned::new().with("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 QueryStringOwned
impl Clone for QueryStringOwned
Source§fn clone(&self) -> QueryStringOwned
fn clone(&self) -> QueryStringOwned
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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 QueryStringOwned
impl Debug for QueryStringOwned
Source§impl Default for QueryStringOwned
impl Default for QueryStringOwned
Source§fn default() -> QueryStringOwned
fn default() -> QueryStringOwned
Returns the “default value” for a type. Read more
Source§impl Display for QueryStringOwned
impl Display for QueryStringOwned
impl Eq for QueryStringOwned
Source§impl PartialEq for QueryStringOwned
impl PartialEq for QueryStringOwned
Source§fn eq(&self, other: &QueryStringOwned) -> bool
fn eq(&self, other: &QueryStringOwned) -> bool
Tests for
self and other values to be equal, and is used by ==.impl StructuralPartialEq for QueryStringOwned
Auto Trait Implementations§
impl Freeze for QueryStringOwned
impl RefUnwindSafe for QueryStringOwned
impl Send for QueryStringOwned
impl Sync for QueryStringOwned
impl Unpin for QueryStringOwned
impl UnsafeUnpin for QueryStringOwned
impl UnwindSafe for QueryStringOwned
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