alux_http/named.rs
1//! States which arguments can be read from a collection of names and values.
2
3use std::collections::{BTreeMap, HashMap};
4
5/// States that an argument is read from a collection of names and values.
6///
7/// A query string, a header collection, and a cookie collection carry names and values. Every
8/// interpretation presents one as a product, so an argument read from one has to be a product too:
9/// a value stating no names of its own is read by nobody, and would fail on the first request that
10/// reached it.
11///
12/// Nothing in a type says whether it is a product, so the type says it here. That turns the mistake
13/// into one the compiler catches rather than one a caller finds:
14///
15/// ```compile_fail
16/// use alux_http::HttpProgramBuilder;
17///
18/// let builder = HttpProgramBuilder;
19/// // A query string carries names and values, and `String` states none.
20/// let _ = builder.op(()).query::<String>();
21/// ```
22///
23/// ```
24/// use alux_http::{HttpProgramBuilder, NamedValuesAlg};
25///
26/// /// What a caller narrows a search by, stated as the query string carries it.
27/// struct Filters {
28/// since: u64,
29/// }
30///
31/// impl NamedValuesAlg for Filters {}
32///
33/// let builder = HttpProgramBuilder;
34/// let _ = builder.op(()).query::<Filters>();
35/// ```
36pub trait NamedValuesAlg {}
37
38/// An association from names to values is what a collection of them is, whatever it maps to.
39impl<Name, Value> NamedValuesAlg for BTreeMap<Name, Value> {}
40
41/// An association from names to values is what a collection of them is, whatever it maps to.
42impl<Name, Value, State> NamedValuesAlg for HashMap<Name, Value, State> {}