use core::fmt;
use core::iter::{FromIterator, FusedIterator};
use core::ops::{Index, IndexMut};
use core::cmp::Ordering;
use core::hash::{Hash, Hasher};
use core::fmt::Formatter;
use core::fmt::Debug;
use crate::cursor::*;
#[cfg(debug_assertions)]
use uuid::{uuid, Uuid};
#[cfg(not(debug_assertions))]
pub(crate) const BAD_HANDLE : HNode = HNode(usize::MAX);
#[cfg(debug_assertions)]
pub(crate) const BAD_HANDLE : HNode =
HNode(usize::MAX,
usize::MAX,
uuid!("deadbeef-dead-beef-dead-beefdeadbeef"));
#[cfg(not(debug_assertions))]
#[repr(transparent)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct HNode(usize);
#[cfg(debug_assertions)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct HNode(usize, usize, Uuid);
impl Default for HNode {
#[inline]
fn default() -> Self {
BAD_HANDLE
}
}
pub(crate) struct Node<T> {
value : Option<T>,
next : HNode,
prev : HNode,
#[cfg(debug_assertions)]
gen : usize,
}
impl<T> Node<T> {
#[cfg(debug_assertions)]
#[inline]
fn new(value: T, gen: usize) -> Self {
Self {
value : Some(value),
next : BAD_HANDLE,
prev : BAD_HANDLE,
gen,
}
}
#[cfg(not(debug_assertions))]
#[inline]
fn new(value: T) -> Self {
Self {
value : Some(value),
next : BAD_HANDLE,
prev : BAD_HANDLE,
}
}
#[cfg(test)]
#[inline(always)]
pub(crate) fn next(&self) -> HNode {
self.next
}
#[cfg(test)]
#[inline(always)]
pub(crate) fn prev(&self) -> HNode {
self.prev
}
}
pub struct LinkedVector<T> {
vec : Vec<Node<T>>,
head : HNode,
recyc : HNode,
len : usize,
#[cfg(debug_assertions)]
uuid : Uuid,
}
impl<T> LinkedVector<T> {
#[inline]
#[must_use]
pub fn new() -> Self {
Self {
vec : Vec::new(),
recyc : BAD_HANDLE,
head : BAD_HANDLE,
len : 0,
#[cfg(debug_assertions)]
uuid : uuid::Uuid::new_v4()
}
}
#[inline]
#[must_use]
pub fn with_capacity(size: usize) -> Self {
Self {
vec : Vec::with_capacity(size),
recyc : BAD_HANDLE,
head : BAD_HANDLE,
len : 0,
#[cfg(debug_assertions)]
uuid : uuid::Uuid::new_v4()
}
}
#[inline]
pub fn append(&mut self, other: &mut Self) {
while let Some(value) = other.pop_front() {
self.push_back(value);
}
other.clear();
}
#[inline]
pub fn back(&self) -> Option<&T> {
if self.is_empty() {
None
} else {
self.back_().unwrap().value.as_ref()
}
}
#[inline]
pub fn back_mut(&mut self) -> Option<&mut T> {
if self.is_empty() {
None
} else {
self.get_mut_(self.get_(self.head).prev).value.as_mut()
}
}
#[inline]
pub fn capacity(&self) -> usize {
self.vec.capacity()
}
#[inline]
pub fn clear(&mut self) {
self.vec.clear();
self.len = 0;
self.head = BAD_HANDLE;
self.recyc = BAD_HANDLE;
}
#[inline]
#[must_use]
pub fn compact(self) -> Self {
self.into_iter().collect()
}
#[inline]
pub fn contains(&self, value: &T) -> bool
where
T: PartialEq
{
self.iter().any(|v| v == value)
}
#[inline]
pub fn cursor(&self, node: HNode) -> Cursor<T> {
Cursor::new(self, node)
}
#[inline]
pub fn cursor_mut(&mut self, node: HNode) -> CursorMut<T> {
CursorMut::new(self, node)
}
#[inline]
pub fn cursor_back(&self) -> Option<Cursor<T>> {
if self.is_empty() {
None
} else {
Some(self.cursor(self.back_node().unwrap()))
}
}
#[inline]
pub fn cursor_back_mut(&mut self) -> Option<CursorMut<T>> {
if self.is_empty() {
None
} else {
Some(self.cursor_mut(self.back_node().unwrap()))
}
}
#[inline]
pub fn cursor_front(&self) -> Option<Cursor<T>> {
if self.is_empty() {
None
} else {
Some(self.cursor(self.front_node().unwrap()))
}
}
#[inline]
pub fn cursor_front_mut(&mut self) -> Option<CursorMut<T>> {
if self.is_empty() {
None
} else {
Some(self.cursor_mut(self.front_node().unwrap()))
}
}
#[inline]
pub fn front(&self) -> Option<&T> {
if self.is_empty() {
None
} else {
self.front_().unwrap().value.as_ref()
}
}
#[inline]
pub fn front_mut(&mut self) -> Option<&mut T> {
if self.is_empty() {
None
} else {
self.get_mut_(self.head).value.as_mut()
}
}
#[inline]
pub fn front_node(&self) -> Option<HNode> {
if self.len == 0 {
None
} else {
Some(self.head)
}
}
#[inline]
pub fn back_node(&self) -> Option<HNode> {
self.front_().map(|node| node.prev)
}
#[inline]
#[cfg(feature = "optionless-accessors")]
pub fn get(&self, node: HNode) -> &T {
self.get_(node).value.as_ref().unwrap()
}
#[inline]
#[cfg(not(feature = "optionless-accessors"))]
pub fn get(&self, node: HNode) -> Option<&T> {
self.get_(node).value.as_ref()
}
#[inline]
#[cfg(feature = "optionless-accessors")]
pub fn get_mut(&mut self, node: HNode) -> &mut T {
self.get_mut_(node).value.as_mut().unwrap()
}
#[inline]
#[cfg(not(feature = "optionless-accessors"))]
pub fn get_mut(&mut self, node: HNode) -> Option<&mut T> {
self.get_mut_(node).value.as_mut()
}
#[inline]
pub fn handle(&self, index: usize) -> Option<HNode> {
if index <= self.len / 2 {
self.handles().nth(index)
} else if index >= self.len {
None
} else {
self.handles().rev().nth(self.len - index - 1)
}
}
#[inline]
pub fn handles(&self) -> Handles<T> {
Handles::new(self)
}
#[inline]
pub fn insert(&mut self, node: HNode, value: T) -> HNode {
self.insert_(Some(node), value)
}
#[inline]
pub fn insert_after(&mut self, node: HNode, value: T) -> HNode {
if let Some(next) = self.next_node(node) {
self.insert_(Some(next), value)
} else {
self.insert_(None, value)
}
}
#[inline]
pub fn is_empty(&self) -> bool {
self.len == 0
}
#[inline]
pub fn iter(&self) -> Iter<T> {
Iter::new(self)
}
#[inline]
pub fn iter_mut(&mut self) -> IterMut<T> {
IterMut::new(self)
}
#[inline]
pub fn len(&self) -> usize {
self.len
}
#[inline]
pub fn next_node(&self, node: HNode) -> Option<HNode> {
let next = self.get_(node).next;
if next == BAD_HANDLE {
None
} else {
Some(next)
}
}
#[inline]
pub fn next_value(&self, node: HNode) -> Option<&T> {
self.next_node(node).and_then(|n| self.get_(n).value.as_ref())
}
#[inline]
pub fn next_value_mut(&mut self, node: HNode) -> Option<&mut T> {
self.next_node(node).and_then(move |n| self.get_mut_(n).value.as_mut())
}
#[inline]
pub fn prev_node(&self, node: HNode) -> Option<HNode> {
if node != self.head {
Some(self.get_(node).prev)
} else {
None
}
}
#[inline]
pub fn prev_value(&self, node: HNode) -> Option<&T> {
self.prev_node(node).and_then(|n| self.get_(n).value.as_ref())
}
#[inline]
pub fn prev_value_mut(&mut self, node: HNode) -> Option<&mut T> {
self.prev_node(node).and_then(move |n| self.get_mut_(n).value.as_mut())
}
#[inline]
pub fn pop_back(&mut self) -> Option<T> {
self.remove_(None)
}
#[inline]
pub fn pop_front(&mut self) -> Option<T> {
if self.is_empty() {
None
} else {
self.remove_(Some(self.head))
}
}
#[inline]
pub fn push_back(&mut self, value: T) -> HNode {
self.insert_(None, value)
}
#[inline]
pub fn push_front(&mut self, value: T) -> HNode {
if self.is_empty() {
self.insert_(None, value)
} else {
self.insert_(Some(self.head), value)
}
}
#[inline]
#[cfg(feature = "optionless-accessors")]
pub fn remove(&mut self, node: HNode) -> T {
self.remove_(Some(node)).unwrap()
}
#[inline]
#[cfg(not(feature = "optionless-accessors"))]
pub fn remove(&mut self, node: HNode) -> Option<T> {
self.remove_(Some(node))
}
#[inline]
pub fn sort(&mut self)
where
T: Ord
{
self.sort_by_(|a, b| a.cmp(b), true);
}
#[inline]
pub fn sort_by<F>(&mut self, compare: F)
where
F: FnMut(&T, &T) -> Ordering,
{
self.sort_by_(compare, true)
}
#[inline]
pub fn sort_by_key<K, F>(&mut self, mut key: F)
where
K: Ord,
F: FnMut(&T) -> K,
{
self.sort_by_(|a, b| key(a).cmp(&key(b)), true);
}
#[inline]
pub fn sort_unstable(&mut self)
where
T: Ord
{
self.sort_by_(|a, b| a.cmp(b), false);
}
#[inline]
pub fn sort_unstable_by<F>(&mut self , compare: F)
where
F: FnMut(&T, &T) -> Ordering,
{
self.sort_by_(compare, false);
}
#[inline]
pub fn sort_unstable_by_key<K, F>(&mut self, mut key: F)
where
K: Ord,
F: FnMut(&T) -> K,
{
self.sort_by_(|a, b| key(a).cmp(&key(b)), false);
}
#[inline]
pub fn to_vec(&self) -> Vec<T>
where
T: Clone
{
self.iter().cloned().collect()
}
#[inline]
fn back_(&self) -> Option<&Node<T>> {
if self.is_empty() {
None
} else {
Some(self.get_(self.get_(self.head).prev))
}
}
#[inline]
fn front_(&self) -> Option<&Node<T>> {
if self.is_empty() {
None
} else {
Some(self.get_(self.head))
}
}
#[inline]
pub(crate) fn insert_(&mut self, node: Option<HNode>, value: T) -> HNode {
if self.is_empty() {
#[cfg(debug_assertions)]
assert!(node.is_none(), "Empty list has no handles.");
let hnew = self.new_node(value);
self.head = hnew;
self.get_mut_(hnew).prev = hnew;
self.len += 1;
hnew
} else {
let hnew = self.new_node(value);
if let Some(hnode) = node {
let hprev = self.get_(hnode).prev;
self.get_mut_(hnew).prev = hprev;
self.get_mut_(hnew).next = hnode;
self.get_mut_(hnode).prev = hnew;
if hnode == self.head {
self.head = hnew;
} else {
self.get_mut_(hprev).next = hnew;
}
} else {
let hnode = self.get_(self.head).prev;
self.get_mut_(hnode).next = hnew;
self.get_mut_(hnew).prev = hnode;
self.get_mut_(self.head).prev = hnew;
}
self.len += 1;
hnew
}
}
#[inline]
pub(crate) fn remove_(&mut self, node: Option<HNode>) -> Option<T> {
if self.is_empty() {
#[cfg(debug_assertions)]
assert!(node.is_none(), "Empty list has no handles.");
None
} else {
let hnode = node.unwrap_or(self.get_(self.head).prev);
if self.len > 1 {
let hprev = self.get_(hnode).prev;
let hnext = self.get_(hnode).next;
if hnext == BAD_HANDLE {
self.get_mut_(self.head).prev = hprev;
} else {
self.get_mut_(hnext).prev = hprev;
}
if hnode == self.head {
self.head = hnext;
} else {
self.get_mut_(hprev).next = hnext;
}
} else {
self.head = BAD_HANDLE;
}
self.len -= 1;
let value = self.get_mut_(hnode).value.take();
self.push_recyc(hnode);
value
}
}
#[inline(always)]
pub(crate) fn get_(&self, node: HNode) -> &Node<T> {
#[cfg(debug_assertions)]
self.check_handle(node);
&self.vec[node.0]
}
#[inline(always)]
pub(crate) fn get_mut_(&mut self, node: HNode) -> &mut Node<T> {
#[cfg(debug_assertions)]
self.check_handle(node);
&mut self.vec[node.0]
}
#[cfg(debug_assertions)]
pub(crate) fn check_handle(&self, node: HNode) {
assert!(node.0 != BAD_HANDLE.0, "Handle is invalid.");
assert!(node.2 == self.uuid, "Handle is not native.");
assert!(node.1 == self.vec[node.0].gen, "Handle has expired.");
}
#[inline]
fn new_node(&mut self, value: T) -> HNode {
if let Some(hnode) = self.pop_recyc() {
#[cfg(debug_assertions)]
{
let gen = self.vec[hnode.0].gen;
self.vec[hnode.0] = Node::new(value, gen);
let mut hnode = hnode;
hnode.1 = gen;
hnode
}
#[cfg(not(debug_assertions))]
{
self.vec[hnode.0] = Node::new(value);
hnode
}
} else {
#[cfg(debug_assertions)]
{
self.vec.push(Node::new(value, 0));
HNode(self.vec.len() - 1, 0, self.uuid)
}
#[cfg(not(debug_assertions))]
{
self.vec.push(Node::new(value));
HNode(self.vec.len() - 1)
}
}
}
#[inline]
fn pop_recyc(&mut self) -> Option<HNode> {
if self.recyc == BAD_HANDLE {
None
} else {
let hnode = self.recyc;
self.recyc = self.vec[hnode.0].next;
self.vec[hnode.0].next = BAD_HANDLE;
Some(hnode)
}
}
#[inline]
fn push_recyc(&mut self, node: HNode) {
self.get_mut_(node).prev = BAD_HANDLE;
if self.recyc == BAD_HANDLE {
self.vec[node.0].next = BAD_HANDLE;
self.recyc = node;
} else {
self.vec[node.0].next = self.recyc;
self.recyc = node;
}
#[cfg(debug_assertions)]
{ self.vec[node.0].gen += 1; }
}
fn sort_by_<F>(&mut self, mut compare: F, stable: bool)
where
F: FnMut(&T, &T) -> Ordering,
{
if self.len < 2 { return; }
let mut handles = self.handles().collect::<Vec<_>>();
if stable {
handles.sort_by(|h1, h2| {
compare(self.vec[h1.0].value.as_ref().unwrap(),
self.vec[h2.0].value.as_ref().unwrap())
});
} else {
handles.sort_unstable_by(|h1, h2| {
compare(self.vec[h1.0].value.as_ref().unwrap(),
self.vec[h2.0].value.as_ref().unwrap())
});
}
for i in 0..self.len - 1 {
self.vec[handles[i].0].next = handles[i + 1];
self.vec[handles[i + 1].0].prev = handles[i];
}
let tail = *handles.last().unwrap();
self.head = handles[0];
self.vec[self.head.0].prev = tail;
self.vec[tail.0].next = BAD_HANDLE;
}
}
impl<T> Clone for LinkedVector<T>
where
T: Clone,
{
#[inline]
fn clone(&self) -> Self {
let mut lv = Self::new();
for v in self.iter() {
lv.push_back(v.clone());
}
lv
}
}
impl<T> Debug for LinkedVector<T>
where
T: Debug,
{
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
write!(f, "LinkedVector(")?;
f.debug_list().entries(self.iter()).finish()?;
write!(f, ")")?;
Ok(())
}
}
impl<T> Default for LinkedVector<T> {
#[inline]
fn default() -> Self {
Self::new()
}
}
impl<T: Eq> Eq for LinkedVector<T> {}
impl<'a, T> Extend<&'a T> for LinkedVector<T>
where
T: Clone,
{
#[inline]
fn extend<I>(&mut self, iter: I)
where
I: IntoIterator<Item = &'a T>,
{
for v in iter {
self.push_back(v.clone());
}
}
}
impl<T> Extend<T> for LinkedVector<T> {
#[inline]
fn extend<I>(&mut self, iter: I)
where
I: IntoIterator<Item = T>,
{
for v in iter {
self.push_back(v);
}
}
}
impl<T, const N: usize> From<[T; N]> for LinkedVector<T> {
#[inline]
fn from(arr: [T; N]) -> Self {
let mut lv = Self::new();
for v in arr {
lv.push_back(v);
}
lv
}
}
impl<T> FromIterator<T> for LinkedVector<T> {
#[inline]
fn from_iter<I>(iter: I) -> Self
where
I: IntoIterator<Item = T>,
{
let mut lv = Self::new();
for v in iter {
lv.push_back(v);
}
lv
}
}
impl<T> Hash for LinkedVector<T>
where
T: Hash,
{
#[inline]
fn hash<H: Hasher>(&self, state: &mut H) {
for v in self.iter() {
v.hash(state);
}
}
}
impl<T> Index<HNode> for LinkedVector<T> {
type Output = T;
#[inline]
fn index(&self, handle: HNode) -> &Self::Output {
#[cfg(feature = "optionless-accessors")]
{ self.get(handle) }
#[cfg(not(feature = "optionless-accessors"))]
{ self.get(handle).unwrap() }
}
}
impl<T> IndexMut<HNode> for LinkedVector<T> {
#[inline]
fn index_mut(&mut self, handle: HNode) -> &mut Self::Output {
#[cfg(feature = "optionless-accessors")]
{ self.get_mut(handle) }
#[cfg(not(feature = "optionless-accessors"))]
{ self.get_mut(handle).unwrap() }
}
}
impl<T> Index<usize> for LinkedVector<T> {
type Output = T;
#[inline]
fn index(&self, index: usize) -> &Self::Output {
self.handle(index)
.and_then(|h| self.vec[h.0].value.as_ref())
.expect("Invalid index")
}
}
impl<T> IndexMut<usize> for LinkedVector<T> {
#[inline]
fn index_mut(&mut self, index: usize) -> &mut Self::Output {
self.handle(index)
.and_then(|h| self.vec[h.0].value.as_mut())
.expect("Invalid index")
}
}
impl<T> PartialEq for LinkedVector<T>
where
T: PartialEq
{
#[inline]
fn eq(&self, other: &Self) -> bool {
self.len() == other.len() && self.iter().eq(other)
}
}
pub struct Handles<'a, T> {
lv : &'a LinkedVector<T>,
hnode : HNode,
hrev : HNode,
len : usize,
}
impl<'a, T> Handles<'a, T> {
#[inline]
pub fn new(lv: &'a LinkedVector<T>) -> Self {
Self {
hnode : lv.head,
hrev : lv.front_().map(|h| h.prev).unwrap_or(BAD_HANDLE),
len : lv.len(),
lv,
}
}
}
impl<'a, T> Iterator for Handles<'a, T> {
type Item = HNode;
#[inline]
fn next(&mut self) -> Option<Self::Item> {
if self.len > 0 {
let hnode = self.hnode;
self.hnode = self.lv.get_(hnode).next;
self.len -= 1;
Some(hnode)
} else {
None
}
}
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
(self.len, Some(self.len))
}
#[inline]
fn last(self) -> Option<Self::Item> {
self.lv.front_().map(|h| h.prev)
}
}
impl<'a, T> DoubleEndedIterator for Handles<'a, T> {
#[inline]
fn next_back(&mut self) -> Option<Self::Item> {
if self.len > 0 {
let hrev = self.hrev;
let node = self.lv.get_(hrev);
self.hrev = node.prev;
self.len -= 1;
Some(hrev)
} else {
None
}
}
}
impl<T> ExactSizeIterator for Handles<'_, T> {}
impl<T> FusedIterator for Handles<'_, T> {}
pub struct Iter<'a, T> {
lv : &'a LinkedVector<T>,
hnode : HNode,
hrev : HNode,
len : usize,
}
impl<'a, T> Iter<'a, T> {
#[inline]
pub fn new(lv: &'a LinkedVector<T>) -> Self {
Self {
hnode : lv.head,
hrev : lv.front_().map(|h| h.prev).unwrap_or(BAD_HANDLE),
len : lv.len(),
lv,
}
}
}
impl<'a, T> Iterator for Iter<'a, T> {
type Item = &'a T;
#[inline]
fn next(&mut self) -> Option<Self::Item> {
if self.len > 0 {
let hnode = self.hnode;
self.hnode = self.lv.get_(hnode).next;
self.len -= 1;
#[cfg(feature = "optionless-accessors")]
{ Some(self.lv.get(hnode)) }
#[cfg(not(feature = "optionless-accessors"))]
{ self.lv.get(hnode) }
} else {
None
}
}
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
(self.len, Some(self.len))
}
#[inline]
fn last(self) -> Option<Self::Item> {
self.lv.back()
}
}
impl<'a, T> DoubleEndedIterator for Iter<'a, T> {
#[inline]
fn next_back(&mut self) -> Option<Self::Item> {
if self.len > 0 {
let hrev = self.hrev;
let node = self.lv.get_(hrev);
self.hrev = node.prev;
self.len -= 1;
#[cfg(feature = "optionless-accessors")]
{ Some(self.lv.get(hrev)) }
#[cfg(not(feature = "optionless-accessors"))]
{ self.lv.get(hrev) }
} else {
None
}
}
}
impl<T> ExactSizeIterator for Iter<'_, T> {}
impl<T> FusedIterator for Iter<'_, T> {}
impl<'a, T> IntoIterator for &'a LinkedVector<T> {
type Item = &'a T;
type IntoIter = Iter<'a, T>;
#[inline]
fn into_iter(self) -> Self::IntoIter {
Iter {
hnode : self.head,
hrev : self.front_().map(|h| h.prev).unwrap_or(BAD_HANDLE),
len : self.len(),
lv : self,
}
}
}
pub struct IterMut<'a, T> {
lv : &'a mut LinkedVector<T>,
hnode : HNode,
hrev : HNode,
len : usize,
}
impl<'a, T> IterMut<'a, T> {
#[inline]
pub fn new(lv: &'a mut LinkedVector<T>) -> Self {
Self {
hnode : lv.head,
hrev : lv.front_().map(|h| h.prev).unwrap_or(BAD_HANDLE),
len : lv.len(),
lv,
}
}
}
impl<'a, T> Iterator for IterMut<'a, T> {
type Item = &'a mut T;
#[inline]
fn next(&mut self) -> Option<Self::Item> {
if self.len > 0 {
let hnode = self.hnode;
self.hnode = self.lv.get_(hnode).next;
self.len -= 1;
#[cfg(feature = "optionless-accessors")]
{ Some(unsafe { &mut *(self.lv.get_mut(hnode) as *mut T) }) }
#[cfg(not(feature = "optionless-accessors"))]
{
Some(unsafe { &mut *(self.lv.get_mut(hnode).unwrap() as *mut T)})
}
} else {
None
}
}
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
(self.len, Some(self.len))
}
#[inline]
fn last(self) -> Option<Self::Item> {
self.lv.back_mut()
}
}
impl<'a, T> DoubleEndedIterator for IterMut<'a, T> {
#[inline]
fn next_back(&mut self) -> Option<Self::Item> {
if self.len > 0 {
let hrev = self.hrev;
let node = self.lv.get_(hrev);
self.hrev = node.prev;
self.len -= 1;
#[cfg(feature = "optionless-accessors")]
{ Some(unsafe { &mut *(self.lv.get_mut(hrev) as *mut T) }) }
#[cfg(not(feature = "optionless-accessors"))]
{
Some(unsafe { &mut *(self.lv.get_mut(hrev).unwrap() as *mut T) })
}
} else {
None
}
}
}
impl<T> ExactSizeIterator for IterMut<'_, T> {}
impl<T> FusedIterator for IterMut<'_, T> {}
impl<'a, T> IntoIterator for &'a mut LinkedVector<T> {
type Item = &'a mut T;
type IntoIter = IterMut<'a, T>;
#[inline]
fn into_iter(self) -> Self::IntoIter {
IterMut {
hnode : self.head,
hrev : self.front_().map(|h| h.prev).unwrap_or(BAD_HANDLE),
len : self.len(),
lv : self,
}
}
}
pub struct IntoIter<T>(LinkedVector<T>);
impl<T> IntoIterator for LinkedVector<T> {
type Item = T;
type IntoIter = IntoIter<T>;
#[inline]
fn into_iter(self) -> Self::IntoIter {
IntoIter(self)
}
}
impl<T> Iterator for IntoIter<T> {
type Item = T;
#[inline]
fn next(&mut self) -> Option<Self::Item> {
self.0.pop_front()
}
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
(self.0.len(), Some(self.0.len()))
}
}
impl<T> DoubleEndedIterator for IntoIter<T> {
#[inline]
fn next_back(&mut self) -> Option<Self::Item> {
self.0.pop_back()
}
}
impl<T> ExactSizeIterator for IntoIter<T> {}
impl<T> FusedIterator for IntoIter<T> {}