1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
//! # Encoding and decoding strategies for query strings.
//!
//! There are various strategies to map Rust types into HTTP query strings. The [`FromQuery`] and
//! [`ToQuery`] encode the logic for how this encoding and decoding is performed. These traits
//! are public as a form of dependency inversion, so that you can override the decoding and
//! encoding strategy being used.
//!
//! These traits are used by the [`History`](crate::History) trait, which allows for modifying the
//! history state, and the [`Location`](crate::Location) struct, which allows for extracting the
//! current location (and this query).
//!
//! ## Default Strategy
//!
//! By default, any Rust type that implements [`Serialize`] or [`Deserialize`](serde::Deserialize)
//! has an implementation of [`ToQuery`] or [`FromQuery`], respectively. This implementation uses
//! the `serde_urlencoded` crate, which implements a standards-compliant `x-www-form-urlencoded`
//! encoder and decoder. Some patterns are not supported by this crate, for example it is not
//! possible to serialize arrays at the moment. If this is an issue for you, consider using the
//! `serde_qs` crate.
//!
//! Example:
//!
//! ```rust,no_run
//! use serde::{Serialize, Deserialize};
//! use gloo_history::{MemoryHistory, History};
//!
//! #[derive(Serialize)]
//! struct Query {
//! name: String,
//! }
//!
//! let query = Query {
//! name: "user".into(),
//! };
//!
//! let history = MemoryHistory::new();
//! history.push_with_query("index.html", &query).unwrap();
//! ```
//!
//! ## Custom Strategy
//!
//! If desired, the [`FromQuery`] and [`ToQuery`] traits can also be manually implemented on
//! types to customize the encoding and decoding strategies. See the documentation for these traits
//! for more detail on how this can be done.
use crateHistoryError;
use ;
use Cow;
use ;
/// Type that can be encoded into a query string.
/// Type that can be decoded from a query string.
/// # Encoding for raw query strings.
///
/// The [`Raw`] wrapper allows for specifying a query string directly, bypassing the encoding. If
/// you use this strategy, you need to take care to escape characters that are not allowed to
/// appear in query strings yourself.
;