Use no public fields for CapacityError
This commit is contained in:
+3
-3
@@ -70,7 +70,7 @@ impl<A: Array<Item=u8>> ArrayString<A> {
|
||||
/// let overflow = string.push('c');
|
||||
///
|
||||
/// assert_eq!(&string[..], "ab");
|
||||
/// assert_eq!(overflow.err().map(|e| e.element), Some('c'));
|
||||
/// assert_eq!(overflow.unwrap_err().element(), 'c');
|
||||
/// ```
|
||||
pub fn push(&mut self, c: char) -> Result<(), CapacityError<char>> {
|
||||
use std::fmt::Write;
|
||||
@@ -93,8 +93,8 @@ impl<A: Array<Item=u8>> ArrayString<A> {
|
||||
/// let overflow2 = string.push_str("ef");
|
||||
///
|
||||
/// assert_eq!(&string[..], "ad");
|
||||
/// assert_eq!(overflow1.err().map(|e| e.element), Some("bc"));
|
||||
/// assert_eq!(overflow2.err().map(|e| e.element), Some("ef"));
|
||||
/// assert_eq!(overflow1.unwrap_err().element(), "bc");
|
||||
/// assert_eq!(overflow2.unwrap_err().element(), "ef");
|
||||
/// ```
|
||||
pub fn push_str<'a>(&mut self, s: &'a str) -> Result<(), CapacityError<&'a str>> {
|
||||
use std::io::Write;
|
||||
|
||||
+7
-3
@@ -36,19 +36,23 @@ unsafe fn new_array<A: Array>() -> A {
|
||||
mem::uninitialized()
|
||||
}
|
||||
|
||||
/// Error value indicating insufficient capacity
|
||||
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
|
||||
pub struct CapacityError<T> {
|
||||
_unused: (),
|
||||
pub element: T,
|
||||
element: T,
|
||||
}
|
||||
|
||||
impl<T> CapacityError<T> {
|
||||
fn new(element: T) -> CapacityError<T> {
|
||||
CapacityError {
|
||||
_unused: (),
|
||||
element: element,
|
||||
}
|
||||
}
|
||||
|
||||
/// Extract the overflowing element
|
||||
pub fn element(self) -> T {
|
||||
self.element
|
||||
}
|
||||
}
|
||||
|
||||
/// A vector with a fixed capacity.
|
||||
|
||||
Reference in New Issue
Block a user