Skip to content

RFC: Replace DList with an owned doubly-linked list, Add trait Deque #7652

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/libextra/container.rs
Original file line number Diff line number Diff line change
@@ -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>;
}
Loading