Add method .into_inner()
This commit is contained in:
+19
@@ -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> {
|
||||
|
||||
Reference in New Issue
Block a user