MCPcopy Create free account
hub / github.com/Lokathor/tinyvec / try_from

Method try_from

src/arrayvec.rs:1466–1482  ·  view source on GitHub ↗

The output has a length equal to that of the slice, with the same capacity as `A`.

(slice: &[T])

Source from the content-addressed store, hash-verified

1464 /// The output has a length equal to that of the slice, with the same capacity
1465 /// as `A`.
1466 fn try_from(slice: &[T]) -> Result<Self, Self::Error> {
1467 if slice.len() > A::CAPACITY {
1468 Err(TryFromSliceError(()))
1469 } else {
1470 let mut arr = ArrayVec::new();
1471 // We do not use ArrayVec::extend_from_slice, because it looks like LLVM
1472 // fails to deduplicate all the length-checking logic between the
1473 // above if and the contents of that method, thus producing much
1474 // slower code. Unlike many of the other optimizations in this
1475 // crate, this one is worth keeping an eye on. I see no reason, for
1476 // any element type, that these should produce different code. But
1477 // they do. (rustc 1.51.0)
1478 arr.set_len(slice.len());
1479 arr.as_mut_slice().clone_from_slice(slice);
1480 Ok(arr)
1481 }
1482 }
1483}
1484
1485impl<A: Array> FromIterator<A::Item> for ArrayVec<A> {

Callers

nothing calls this directly

Calls 4

TryFromSliceErrorClass · 0.85
lenMethod · 0.45
set_lenMethod · 0.45
as_mut_sliceMethod · 0.45

Tested by

no test coverage detected