MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / from_elem

Method from_elem

crates/core/src/alloc/vec.rs:102–116  ·  view source on GitHub ↗
(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

Calls 4

OkFunction · 0.85
getMethod · 0.45
pushMethod · 0.45
try_cloneMethod · 0.45

Tested by

no test coverage detected