File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -246,6 +246,29 @@ where
246246 }
247247}
248248
249+ #[ cfg( feature = "std" ) ]
250+ impl < Input > FromIterator < ( Input , Input ) > for URLSearchParams
251+ where
252+ Input : AsRef < str > ,
253+ {
254+ /// Converts an iterator to URLSearchParams
255+ ///
256+ /// ```
257+ /// use ada_url::URLSearchParams;
258+ /// let iterator = std::iter::repeat(("hello", "world")).take(5);
259+ /// let params = URLSearchParams::from_iter(iterator);
260+ /// assert_eq!(params.len(), 5);
261+ /// ```
262+ fn from_iter < T : IntoIterator < Item = ( Input , Input ) > > ( iter : T ) -> Self {
263+ let mut params = URLSearchParams :: parse ( "" )
264+ . expect ( "Failed to parse empty string. This is likely due to a bug" ) ;
265+ for item in iter {
266+ params. append ( item. 0 . as_ref ( ) , item. 1 . as_ref ( ) ) ;
267+ }
268+ params
269+ }
270+ }
271+
249272pub struct URLSearchParamsKeysIterator < ' a > {
250273 iterator : * mut ffi:: ada_url_search_params_keys_iter ,
251274 _phantom : core:: marker:: PhantomData < & ' a str > ,
You can’t perform that action at this time.
0 commit comments