Skip to content

Commit

Permalink
Error implementation for TryFromSliceError (#160)
Browse files Browse the repository at this point in the history
* Fix spelling of 'length'

* Add Error implementation to TryFromSliceError
  • Loading branch information
ajtribick authored Apr 23, 2022
1 parent 7c85b93 commit a53c254
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/arrayvec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1271,7 +1271,7 @@ impl<A: Array> From<A> for ArrayVec<A> {
.as_slice()
.len()
.try_into()
.expect("ArrayVec::from> lenght must be in range 0..=u16::MAX");
.expect("ArrayVec::from> length must be in range 0..=u16::MAX");
Self { len, data }
}
}
Expand All @@ -1281,6 +1281,15 @@ impl<A: Array> From<A> for ArrayVec<A> {
#[derive(Debug, Copy, Clone)]
pub struct TryFromSliceError(());

impl core::fmt::Display for TryFromSliceError {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
f.write_str("could not convert slice to ArrayVec")
}
}

#[cfg(feature = "std")]
impl std::error::Error for TryFromSliceError {}

impl<T, A> TryFrom<&'_ [T]> for ArrayVec<A>
where
T: Clone + Default,
Expand Down

0 comments on commit a53c254

Please sign in to comment.