Skip to content

Commit aa37bf0

Browse files
committed
add extend trait to urlsearchparams
1 parent 1793feb commit aa37bf0

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/url_search_params.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,28 @@ impl core::fmt::Display for URLSearchParams {
224224
}
225225
}
226226

227+
#[cfg(feature = "std")]
228+
impl<Input> Extend<(Input, Input)> for URLSearchParams
229+
where
230+
Input: AsRef<str>,
231+
{
232+
/// Supports extending URLSearchParams through an iterator.
233+
///
234+
///```
235+
/// use ada_url::URLSearchParams;
236+
/// let mut params = URLSearchParams::parse("a=1&b=2")
237+
/// .expect("This is a valid URLSearchParams. Should have parsed it.");
238+
/// assert_eq!(params.len(), 2);
239+
/// params.extend([("foo", "bar")]);
240+
/// assert_eq!(params.len(), 3);
241+
/// ```
242+
fn extend<T: IntoIterator<Item = (Input, Input)>>(&mut self, iter: T) {
243+
for item in iter {
244+
self.append(item.0.as_ref(), item.1.as_ref());
245+
}
246+
}
247+
}
248+
227249
pub struct URLSearchParamsKeysIterator<'a> {
228250
iterator: *mut ffi::ada_url_search_params_keys_iter,
229251
_phantom: core::marker::PhantomData<&'a str>,

0 commit comments

Comments
 (0)