Struct QueryString

Source
pub struct QueryString { /* private fields */ }
๐Ÿ‘ŽDeprecated: This crate has been renamed to http_tiny; youโ€™re using an outdated version
Expand description

A query string

ยงWarning

The query parser is pretty simple and basically parses any key or key= or key=value component without further validation.

The following rules apply:

  • the query string MUST NOT begin with a ? โ€“ itโ€™s not a bug, itโ€™s a feature: this allows the parser to parse query query strings in the body (e.g. from HTML forms)
  • keys donโ€™t need a value (i.e. key0&key1 is valid)
  • keys can have an empty value (i.e. key0=&key1= is valid)
  • keys can have a non-empty value (i.e. key0=value0&key1=value1 is valid)
  • empty keys/key-value pairs are ignored (i.e. & evaluates to [], key0&&key1 evaluates to ["key0": "", "key1": ""] and =value0&key1=value1& evaluates to ["key1": "value1"])

Implementationsยง

Sourceยง

impl QueryString

Source

pub fn new() -> Self

๐Ÿ‘ŽDeprecated: This crate has been renamed to http_tiny; youโ€™re using an outdated version

Creates a new header field map

Source

pub fn get<T>(&self, name: T) -> Option<&[u8]>
where T: AsRef<[u8]>,

๐Ÿ‘ŽDeprecated: This crate has been renamed to http_tiny; youโ€™re using an outdated version

Gets the value for the field with the given name

Source

pub fn set<A, B>(&mut self, name: A, value: B)
where A: Into<Vec<u8>>, B: Into<Vec<u8>>,

๐Ÿ‘ŽDeprecated: This crate has been renamed to http_tiny; youโ€™re using an outdated version

Sets the value for a fiels with the given name

Source

pub fn read<T>(source: &mut T) -> Result<Self>
where T: BufRead,

๐Ÿ‘ŽDeprecated: This crate has been renamed to http_tiny; youโ€™re using an outdated version

Reads a query string

Source

pub fn write<T>(self, output: &mut T) -> Result
where T: Write,

๐Ÿ‘ŽDeprecated: This crate has been renamed to http_tiny; youโ€™re using an outdated version

Writes the query string

Methods from Deref<Target = BTreeMap<Vec<u8>, Vec<u8>>>ยง

1.0.0 ยท Source

pub fn get<Q>(&self, key: &Q) -> Option<&V>
where K: Borrow<Q> + Ord, Q: Ord + ?Sized,

Returns a reference to the value corresponding to the key.

The key may be any borrowed form of the mapโ€™s key type, but the ordering on the borrowed form must match the ordering on the key type.

ยงExamples
use std::collections::BTreeMap;

let mut map = BTreeMap::new();
map.insert(1, "a");
assert_eq!(map.get(&1), Some(&"a"));
assert_eq!(map.get(&2), None);
1.40.0 ยท Source

pub fn get_key_value<Q>(&self, k: &Q) -> Option<(&K, &V)>
where K: Borrow<Q> + Ord, Q: Ord + ?Sized,

Returns the key-value pair corresponding to the supplied key. This is potentially useful:

  • for key types where non-identical keys can be considered equal;
  • for getting the &K stored key value from a borrowed &Q lookup key; or
  • for getting a reference to a key with the same lifetime as the collection.

The supplied key may be any borrowed form of the mapโ€™s key type, but the ordering on the borrowed form must match the ordering on the key type.

ยงExamples
use std::cmp::Ordering;
use std::collections::BTreeMap;

#[derive(Clone, Copy, Debug)]
struct S {
    id: u32,
    name: &'static str, // ignored by equality and ordering operations
}

impl PartialEq for S {
    fn eq(&self, other: &S) -> bool {
        self.id == other.id
    }
}

impl Eq for S {}

impl PartialOrd for S {
    fn partial_cmp(&self, other: &S) -> Option<Ordering> {
        self.id.partial_cmp(&other.id)
    }
}

impl Ord for S {
    fn cmp(&self, other: &S) -> Ordering {
        self.id.cmp(&other.id)
    }
}

let j_a = S { id: 1, name: "Jessica" };
let j_b = S { id: 1, name: "Jess" };
let p = S { id: 2, name: "Paul" };
assert_eq!(j_a, j_b);

let mut map = BTreeMap::new();
map.insert(j_a, "Paris");
assert_eq!(map.get_key_value(&j_a), Some((&j_a, &"Paris")));
assert_eq!(map.get_key_value(&j_b), Some((&j_a, &"Paris"))); // the notable case
assert_eq!(map.get_key_value(&p), None);
1.66.0 ยท Source

pub fn first_key_value(&self) -> Option<(&K, &V)>
where K: Ord,

Returns the first key-value pair in the map. The key in this pair is the minimum key in the map.

ยงExamples
use std::collections::BTreeMap;

let mut map = BTreeMap::new();
assert_eq!(map.first_key_value(), None);
map.insert(1, "b");
map.insert(2, "a");
assert_eq!(map.first_key_value(), Some((&1, &"b")));
1.66.0 ยท Source

pub fn last_key_value(&self) -> Option<(&K, &V)>
where K: Ord,

Returns the last key-value pair in the map. The key in this pair is the maximum key in the map.

ยงExamples
use std::collections::BTreeMap;

let mut map = BTreeMap::new();
map.insert(1, "b");
map.insert(2, "a");
assert_eq!(map.last_key_value(), Some((&2, &"a")));
1.0.0 ยท Source

pub fn contains_key<Q>(&self, key: &Q) -> bool
where K: Borrow<Q> + Ord, Q: Ord + ?Sized,

Returns true if the map contains a value for the specified key.

The key may be any borrowed form of the mapโ€™s key type, but the ordering on the borrowed form must match the ordering on the key type.

ยงExamples
use std::collections::BTreeMap;

let mut map = BTreeMap::new();
map.insert(1, "a");
assert_eq!(map.contains_key(&1), true);
assert_eq!(map.contains_key(&2), false);
1.17.0 ยท Source

pub fn range<T, R>(&self, range: R) -> Range<'_, K, V>
where T: Ord + ?Sized, K: Borrow<T> + Ord, R: RangeBounds<T>,

Constructs a double-ended iterator over a sub-range of elements in the map. The simplest way is to use the range syntax min..max, thus range(min..max) will yield elements from min (inclusive) to max (exclusive). The range may also be entered as (Bound<T>, Bound<T>), so for example range((Excluded(4), Included(10))) will yield a left-exclusive, right-inclusive range from 4 to 10.

ยงPanics

Panics if range start > end. Panics if range start == end and both bounds are Excluded.

ยงExamples
use std::collections::BTreeMap;
use std::ops::Bound::Included;

let mut map = BTreeMap::new();
map.insert(3, "a");
map.insert(5, "b");
map.insert(8, "c");
for (&key, &value) in map.range((Included(&4), Included(&8))) {
    println!("{key}: {value}");
}
assert_eq!(Some((&5, &"b")), map.range(4..).next());
1.0.0 ยท Source

pub fn iter(&self) -> Iter<'_, K, V>

Gets an iterator over the entries of the map, sorted by key.

ยงExamples
use std::collections::BTreeMap;

let mut map = BTreeMap::new();
map.insert(3, "c");
map.insert(2, "b");
map.insert(1, "a");

for (key, value) in map.iter() {
    println!("{key}: {value}");
}

let (first_key, first_value) = map.iter().next().unwrap();
assert_eq!((*first_key, *first_value), (1, "a"));
1.0.0 ยท Source

pub fn keys(&self) -> Keys<'_, K, V>

Gets an iterator over the keys of the map, in sorted order.

ยงExamples
use std::collections::BTreeMap;

let mut a = BTreeMap::new();
a.insert(2, "b");
a.insert(1, "a");

let keys: Vec<_> = a.keys().cloned().collect();
assert_eq!(keys, [1, 2]);
1.0.0 ยท Source

pub fn values(&self) -> Values<'_, K, V>

Gets an iterator over the values of the map, in order by key.

ยงExamples
use std::collections::BTreeMap;

let mut a = BTreeMap::new();
a.insert(1, "hello");
a.insert(2, "goodbye");

let values: Vec<&str> = a.values().cloned().collect();
assert_eq!(values, ["hello", "goodbye"]);
1.0.0 ยท Source

pub fn len(&self) -> usize

Returns the number of elements in the map.

ยงExamples
use std::collections::BTreeMap;

let mut a = BTreeMap::new();
assert_eq!(a.len(), 0);
a.insert(1, "a");
assert_eq!(a.len(), 1);
1.0.0 ยท Source

pub fn is_empty(&self) -> bool

Returns true if the map contains no elements.

ยงExamples
use std::collections::BTreeMap;

let mut a = BTreeMap::new();
assert!(a.is_empty());
a.insert(1, "a");
assert!(!a.is_empty());
Source

pub fn lower_bound<Q>(&self, bound: Bound<&Q>) -> Cursor<'_, K, V>
where K: Borrow<Q> + Ord, Q: Ord + ?Sized,

๐Ÿ”ฌThis is a nightly-only experimental API. (btree_cursors)

Returns a Cursor pointing at the gap before the smallest key greater than the given bound.

Passing Bound::Included(x) will return a cursor pointing to the gap before the smallest key greater than or equal to x.

Passing Bound::Excluded(x) will return a cursor pointing to the gap before the smallest key greater than x.

Passing Bound::Unbounded will return a cursor pointing to the gap before the smallest key in the map.

ยงExamples
#![feature(btree_cursors)]

use std::collections::BTreeMap;
use std::ops::Bound;

let map = BTreeMap::from([
    (1, "a"),
    (2, "b"),
    (3, "c"),
    (4, "d"),
]);

let cursor = map.lower_bound(Bound::Included(&2));
assert_eq!(cursor.peek_prev(), Some((&1, &"a")));
assert_eq!(cursor.peek_next(), Some((&2, &"b")));

let cursor = map.lower_bound(Bound::Excluded(&2));
assert_eq!(cursor.peek_prev(), Some((&2, &"b")));
assert_eq!(cursor.peek_next(), Some((&3, &"c")));

let cursor = map.lower_bound(Bound::Unbounded);
assert_eq!(cursor.peek_prev(), None);
assert_eq!(cursor.peek_next(), Some((&1, &"a")));
Source

pub fn upper_bound<Q>(&self, bound: Bound<&Q>) -> Cursor<'_, K, V>
where K: Borrow<Q> + Ord, Q: Ord + ?Sized,

๐Ÿ”ฌThis is a nightly-only experimental API. (btree_cursors)

Returns a Cursor pointing at the gap after the greatest key smaller than the given bound.

Passing Bound::Included(x) will return a cursor pointing to the gap after the greatest key smaller than or equal to x.

Passing Bound::Excluded(x) will return a cursor pointing to the gap after the greatest key smaller than x.

Passing Bound::Unbounded will return a cursor pointing to the gap after the greatest key in the map.

ยงExamples
#![feature(btree_cursors)]

use std::collections::BTreeMap;
use std::ops::Bound;

let map = BTreeMap::from([
    (1, "a"),
    (2, "b"),
    (3, "c"),
    (4, "d"),
]);

let cursor = map.upper_bound(Bound::Included(&3));
assert_eq!(cursor.peek_prev(), Some((&3, &"c")));
assert_eq!(cursor.peek_next(), Some((&4, &"d")));

let cursor = map.upper_bound(Bound::Excluded(&3));
assert_eq!(cursor.peek_prev(), Some((&2, &"b")));
assert_eq!(cursor.peek_next(), Some((&3, &"c")));

let cursor = map.upper_bound(Bound::Unbounded);
assert_eq!(cursor.peek_prev(), Some((&4, &"d")));
assert_eq!(cursor.peek_next(), None);

Trait Implementationsยง

Sourceยง

impl Clone for QueryString

Sourceยง

fn clone(&self) -> QueryString

Returns a duplicate of the value. Read more
1.0.0 ยท Sourceยง

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Sourceยง

impl Debug for QueryString

Sourceยง

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Sourceยง

impl Default for QueryString

Sourceยง

fn default() -> QueryString

Returns the โ€œdefault valueโ€ for a type. Read more
Sourceยง

impl Deref for QueryString

Sourceยง

type Target = BTreeMap<Vec<u8>, Vec<u8>>

The resulting type after dereferencing.
Sourceยง

fn deref(&self) -> &Self::Target

Dereferences the value.
Sourceยง

impl<K, V> FromIterator<(K, V)> for QueryString
where K: Into<Vec<u8>>, V: Into<Vec<u8>>,

Sourceยง

fn from_iter<T: IntoIterator<Item = (K, V)>>(pairs: T) -> Self

Creates a value from an iterator. Read more
Sourceยง

impl IntoIterator for QueryString

Sourceยง

type Item = <BTreeMap<Vec<u8>, Vec<u8>> as IntoIterator>::Item

The type of the elements being iterated over.
Sourceยง

type IntoIter = <BTreeMap<Vec<u8>, Vec<u8>> as IntoIterator>::IntoIter

Which kind of iterator are we turning this into?
Sourceยง

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementationsยง

Blanket Implementationsยง

Sourceยง

impl<T> Any for T
where T: 'static + ?Sized,

Sourceยง

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Sourceยง

impl<T> Borrow<T> for T
where T: ?Sized,

Sourceยง

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Sourceยง

impl<T> BorrowMut<T> for T
where T: ?Sized,

Sourceยง

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Sourceยง

impl<T> CloneToUninit for T
where T: Clone,

Sourceยง

unsafe fn clone_to_uninit(&self, dest: *mut u8)

๐Ÿ”ฌThis is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Sourceยง

impl<T> From<T> for T

Sourceยง

fn from(t: T) -> T

Returns the argument unchanged.

Sourceยง

impl<T, U> Into<U> for T
where U: From<T>,

Sourceยง

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Sourceยง

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Sourceยง

type Target = T

๐Ÿ”ฌThis is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Sourceยง

impl<T> ToOwned for T
where T: Clone,

Sourceยง

type Owned = T

The resulting type after obtaining ownership.
Sourceยง

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Sourceยง

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Sourceยง

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Sourceยง

type Error = Infallible

The type returned in the event of a conversion error.
Sourceยง

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Sourceยง

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Sourceยง

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Sourceยง

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.