1 // SPDX-License-Identifier: GPL-2.0 2 3 //! Errors for the [`Vec`] type. 4 5 use core::fmt::{self, Debug, Formatter}; 6 use kernel::prelude::*; 7 8 /// Error type for [`Vec::push_within_capacity`]. 9 pub struct PushError<T>(pub T); 10 11 impl<T> Debug for PushError<T> { 12 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { 13 write!(f, "Not enough capacity") 14 } 15 } 16 17 impl<T> From<PushError<T>> for Error { 18 fn from(_: PushError<T>) -> Error { 19 // Returning ENOMEM isn't appropriate because the system is not out of memory. The vector 20 // is just full and we are refusing to resize it. 21 EINVAL 22 } 23 } 24 25 /// Error type for [`Vec::remove`]. 26 pub struct RemoveError; 27 28 impl Debug for RemoveError { 29 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { 30 write!(f, "Index out of bounds") 31 } 32 } 33 34 impl From<RemoveError> for Error { 35 fn from(_: RemoveError) -> Error { 36 EINVAL 37 } 38 } 39