diff options
| author | blake2-ppc <blake2-ppc> | 2013-07-10 15:27:14 +0200 |
|---|---|---|
| committer | blake2-ppc <blake2-ppc> | 2013-07-11 15:54:35 +0200 |
| commit | 6a95e49fc5bad1367f597bf0eeab7197c9ca226a (patch) | |
| tree | 4c4094afd8119f7b0dd073cb7d466de2302bce4c | |
| parent | 92842d6516d2c5d92bad553585340f2ae3284308 (diff) | |
extra: Add mod container with trait Deque
| -rw-r--r-- | src/libextra/container.rs | 40 | ||||
| -rw-r--r-- | src/libextra/extra.rs | 1 |
2 files changed, 41 insertions, 0 deletions
diff --git a/src/libextra/container.rs b/src/libextra/container.rs new file mode 100644 index 00000000000..fe622289b29 --- /dev/null +++ b/src/libextra/container.rs @@ -0,0 +1,40 @@ +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//! Container traits for extra + +use std::container::Mutable; + +/// A double-ended sequence that allows querying, insertion and deletion at both ends. +pub trait Deque<T> : Mutable { + /// Provide a reference to the front element, or None if the sequence is empty + fn front<'a>(&'a self) -> Option<&'a T>; + + /// Provide a mutable reference to the front element, or None if the sequence is empty + fn front_mut<'a>(&'a mut self) -> Option<&'a mut T>; + + /// Provide a reference to the back element, or None if the sequence is empty + fn back<'a>(&'a self) -> Option<&'a T>; + + /// Provide a mutable reference to the back element, or None if the sequence is empty + fn back_mut<'a>(&'a mut self) -> Option<&'a mut T>; + + /// Insert an element first in the sequence + fn push_front(&mut self, elt: T); + + /// Insert an element last in the sequence + fn push_back(&mut self, elt: T); + + /// Remove the last element and return it, or None if the sequence is empty + fn pop_back(&mut self) -> Option<T>; + + /// Remove the first element and return it, or None if the sequence is empty + fn pop_front(&mut self) -> Option<T>; +} diff --git a/src/libextra/extra.rs b/src/libextra/extra.rs index 7bec1d600b4..18322fcda59 100644 --- a/src/libextra/extra.rs +++ b/src/libextra/extra.rs @@ -67,6 +67,7 @@ pub mod flatpipes; // Collections +pub mod container; pub mod bitv; pub mod deque; pub mod fun_treemap; |
