Add method CapacityError::simplify

This is needed so that CapacityError<&str> isn't prohibitively difficult
to use. It converts to CapacityError<()>.
This commit is contained in:
bluss
2016-01-13 12:55:29 +01:00
parent d991c17a25
commit 2046e3f726
+6 -1
View File
@@ -705,7 +705,7 @@ impl<A: Array<Item=u8>> io::Write for ArrayVec<A> {
/// Error value indicating insufficient capacity /// Error value indicating insufficient capacity
#[derive(Clone, Copy, Eq, Ord, PartialEq, PartialOrd)] #[derive(Clone, Copy, Eq, Ord, PartialEq, PartialOrd)]
pub struct CapacityError<T> { pub struct CapacityError<T = ()> {
element: T, element: T,
} }
@@ -720,6 +720,11 @@ impl<T> CapacityError<T> {
pub fn element(self) -> T { pub fn element(self) -> T {
self.element self.element
} }
/// Convert into a `CapacityError` that does not carry an element.
pub fn simplify(self) -> CapacityError {
CapacityError { element: () }
}
} }
const CAPERROR: &'static str = "insufficient capacity"; const CAPERROR: &'static str = "insufficient capacity";