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
// This file is part of helpers4.
// Copyright (C) 2025 baxyz
// SPDX-License-Identifier: LGPL-3.0-or-later
use percent_encode;
/// Builds a query string (`a=1&b=two`) from key-value pairs, percent-encoding both sides.
///
/// Pairs keep their order and repeated keys are kept. A space becomes `%20` (not `+`), which every
/// URL parser reads back correctly. The result has no leading `?`. It is the inverse of
/// [`parse_query`](super::parse_query).
///
/// # Arguments
///
/// - `pairs` - The keys and values, anything that iterates over `(key, value)` of string-likes.
///
/// # Returns
///
/// The encoded query string, empty when there are no pairs.
///
/// # Examples
///
/// ```
/// use helpers4::url::build_query;
///
/// assert_eq!(build_query([("q", "rust lang"), ("page", "2")]), "q=rust%20lang&page=2");
/// assert_eq!(build_query(Vec::<(&str, &str)>::new()), "");
/// ```