Skip to content

Commit 534532d

Browse files
author
Vurich
committed
Add from_buf method
1 parent 7bda532 commit 534532d

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

lib.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,25 @@ impl<A: Array> SmallVec<A> {
289289
}
290290
}
291291

292+
/// Constructs a new `SmallVec` on the stack from an `A` without
293+
/// copying elements.
294+
///
295+
/// ```rust
296+
/// use smallvec::SmallVec;
297+
///
298+
/// let buf = [1, 2, 3, 4, 5];
299+
/// let small_vec: SmallVec<_> = SmallVec::from_buf(buf);
300+
///
301+
/// assert_eq!(&*small_vec, &[1, 2, 3, 4, 5]);
302+
/// ```
303+
#[inline]
304+
pub fn from_buf(buf: A) -> SmallVec<A> {
305+
SmallVec {
306+
len: A::size(),
307+
data: SmallVecData::Inline { array: buf },
308+
}
309+
}
310+
292311
/// Sets the length of a vector.
293312
///
294313
/// This will explicitly set the size of the vector, without actually

0 commit comments

Comments
 (0)