Add method .into_inner()

This commit is contained in:
root
2015-06-22 16:33:22 +02:00
parent 66d5d9a12e
commit 5c50c4dbc7
2 changed files with 59 additions and 0 deletions
+19
View File
@@ -323,6 +323,25 @@ impl<A: Array> ArrayVec<A> {
}
}
}
/// Return the inner fixed size array, if it is full to its capacity.
///
/// Return an **Ok** value with the array if length equals capacity,
/// return an **Err** with self otherwise.
///
/// **Note:** This function may incur unproportionally large overhead
/// to move the array out, its performance is not optimal.
pub fn into_inner(self) -> Result<A, Self> {
if self.len() < self.capacity() {
Err(self)
} else {
unsafe {
let array = ptr::read(&*self.xs);
mem::forget(self);
Ok(array)
}
}
}
}
impl<A: Array> Deref for ArrayVec<A> {