extend_ref/
lib.rs

1#![no_std]
2
3//! # `extend-ref`
4//!
5//! A wrapper struct that implements `Extend` for mutable references.
6//!
7//!
8//! ```rust
9//! use extend_ref::ExtendRef;
10//!
11//! fn unzip_on_refs(
12//!     mut squares: &mut impl Extend<i32>,
13//!     mut cubes: &mut impl Extend<i32>,
14//!     mut tesseracts: &mut impl Extend<i32>
15//! ) {
16//!     // Create an iterator of a 3-tuple
17//!     let iter = (0i32..10).map(|i| (i * i, i.pow(3), i.pow(4)));
18//!
19//!     // Unzip the iterator into the three referenced collections
20//!     (ExtendRef(squares), ExtendRef(cubes), ExtendRef(tesseracts)).extend(iter);
21//! }
22//! ```
23//!
24
25
26
27pub struct ExtendRef<'a, T>(pub &'a mut T);
28
29impl<'a, A, T: Extend<A>> Extend<A> for ExtendRef<'a, T> {
30	fn extend<U>(&mut self, iter: U)
31	where
32		U: IntoIterator<Item = A>,
33	{
34		self.0.extend(iter)
35	}
36}