Method
from_elem
(elem: T, len: NonZeroUsize)
Source from the content-addressed store, hash-verified
| 100 | #[doc(hidden)] |
| 101 | #[inline] |
| 102 | pub fn from_elem(elem: T, len: NonZeroUsize) -> Result<Self, OutOfMemory> |
| 103 | where |
| 104 | T: TryClone, |
| 105 | { |
| 106 | let mut v = Self::with_capacity(len.get())?; |
| 107 | |
| 108 | // Minimize calls to `TryClone` by always pushing `elem` itself as the |
| 109 | // last element. |
| 110 | for _ in 0..len.get() - 1 { |
| 111 | v.push(elem.try_clone()?)?; |
| 112 | } |
| 113 | v.push(elem)?; |
| 114 | |
| 115 | Ok(v) |
| 116 | } |
| 117 | |
| 118 | /// Same as [`std::vec::Vec::reserve`] but returns an error on allocation |
| 119 | /// failure. |
Callers
nothing calls this directly
Tested by
no test coverage detected