|
| 1 | +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT |
| 2 | +// file at the top-level directory of this distribution and at |
| 3 | +// http://rust-lang.org/COPYRIGHT. |
| 4 | +// |
| 5 | +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 6 | +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 7 | +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
| 8 | +// option. This file may not be copied, modified, or distributed |
| 9 | +// except according to those terms. |
| 10 | + |
| 11 | +//! Container traits for extra |
| 12 | +
|
| 13 | +use std::container::Mutable; |
| 14 | + |
| 15 | +/// A double-ended sequence that allows querying, insertion and deletion at both ends. |
| 16 | +pub trait Deque<T> : Mutable { |
| 17 | + /// Provide a reference to the front element, or None if the sequence is empty |
| 18 | + fn front<'a>(&'a self) -> Option<&'a T>; |
| 19 | + |
| 20 | + /// Provide a mutable reference to the front element, or None if the sequence is empty |
| 21 | + fn front_mut<'a>(&'a mut self) -> Option<&'a mut T>; |
| 22 | + |
| 23 | + /// Provide a reference to the back element, or None if the sequence is empty |
| 24 | + fn back<'a>(&'a self) -> Option<&'a T>; |
| 25 | + |
| 26 | + /// Provide a mutable reference to the back element, or None if the sequence is empty |
| 27 | + fn back_mut<'a>(&'a mut self) -> Option<&'a mut T>; |
| 28 | + |
| 29 | + /// Insert an element first in the sequence |
| 30 | + fn push_front(&mut self, elt: T); |
| 31 | + |
| 32 | + /// Insert an element last in the sequence |
| 33 | + fn push_back(&mut self, elt: T); |
| 34 | + |
| 35 | + /// Remove the last element and return it, or None if the sequence is empty |
| 36 | + fn pop_back(&mut self) -> Option<T>; |
| 37 | + |
| 38 | + /// Remove the first element and return it, or None if the sequence is empty |
| 39 | + fn pop_front(&mut self) -> Option<T>; |
| 40 | +} |
0 commit comments