Skip to content

Commit caac305

Browse files
committed
Add append and append_into functions
1 parent eedcde1 commit caac305

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,24 @@
33
All notable changes to this project will be documented in this file.
44
This project uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
55

6+
## [0.3.0] - 2023-07-08
7+
8+
### Added
9+
10+
- Added the `append` and `append_into` functions.
11+
612
## [0.2.0] - 2023-07-07
713

814
### Added
915

10-
- Added the `with_opt_value` and `push_opt` helper methods.
16+
- Added the `with_opt_value` and `push_opt` functions.
1117

1218
## [0.1.0] - 2023-07-07
1319

1420
### Internal
1521

1622
- 🎉 Initial release.
1723

24+
[0.3.0]: https://github.com/sunsided/query-string-builder/releases/tag/0.3.0
1825
[0.2.0]: https://github.com/sunsided/query-string-builder/releases/tag/0.2.0
1926
[0.1.0]: https://github.com/sunsided/query-string-builder/releases/tag/0.1.0

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "query-string-builder"
33
description = "A query string builder for percent encoding key-value pairs"
44
authors = ["Markus Mayer"]
5-
version = "0.2.0"
5+
version = "0.3.0"
66
edition = "2021"
77
repository = "https://github.com/sunsided/query-string-builder"
88
keywords = ["url", "query-string", "query-argument"]

src/lib.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,49 @@ impl<'a> QueryString<'a> {
156156
pub fn is_empty(&self) -> bool {
157157
self.pairs.is_empty()
158158
}
159+
160+
/// Appends another query string builder's values.
161+
///
162+
/// ## Example
163+
///
164+
/// ```
165+
/// use query_string_builder::QueryString;
166+
///
167+
/// let mut qs = QueryString::new().with_value("q", "apple");
168+
/// let more = QueryString::new().with_value("q", "pear");
169+
///
170+
/// qs.append(more);
171+
///
172+
/// assert_eq!(
173+
/// format!("https://example.com/{qs}"),
174+
/// "https://example.com/?q=apple&q=pear"
175+
/// );
176+
/// ```
177+
pub fn append(&mut self, mut other: QueryString<'a>) {
178+
self.pairs.append(&mut other.pairs)
179+
}
180+
181+
/// Appends another query string builder's values, consuming both types.
182+
///
183+
/// ## Example
184+
///
185+
/// ```
186+
/// use query_string_builder::QueryString;
187+
///
188+
/// let qs = QueryString::new().with_value("q", "apple");
189+
/// let more = QueryString::new().with_value("q", "pear");
190+
///
191+
/// let qs = qs.append_into(more);
192+
///
193+
/// assert_eq!(
194+
/// format!("https://example.com/{qs}"),
195+
/// "https://example.com/?q=apple&q=pear"
196+
/// );
197+
/// ```
198+
pub fn append_into(mut self, mut other: QueryString<'a>) -> Self {
199+
self.pairs.append(&mut other.pairs);
200+
self
201+
}
159202
}
160203

161204
impl<'a> Display for QueryString<'a> {

0 commit comments

Comments
 (0)