Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
c86873bd
R
Rust
项目概览
int
/
Rust
11 个月 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c86873bd
编写于
7月 20, 2014
作者:
J
Jonas Hietala
提交者:
Alex Crichton
7月 21, 2014
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Document Deque.
上级
ec70f2bb
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
173 addition
and
10 deletion
+173
-10
src/libcollections/lib.rs
src/libcollections/lib.rs
+173
-10
未找到文件。
src/libcollections/lib.rs
浏览文件 @
c86873bd
...
...
@@ -327,33 +327,196 @@ pub trait MutableSet<T>: Set<T> + Mutable {
/// A double-ended sequence that allows querying, insertion and deletion at both
/// ends.
///
/// # Example
///
/// With a `Deque` we can simulate a stack:
///
/// ```
/// use std::collections::{RingBuf, Deque};
///
/// let mut stack = RingBuf::new();
/// stack.push_front(1i);
/// stack.push_front(2i);
/// stack.push_front(3i);
///
/// // Will print 3, 2, 1
/// while !stack.is_empty() {
/// let x = stack.pop_front().unwrap();
/// println!("{}", x);
/// }
/// ```
///
/// We can simulate a queue:
///
/// ```
/// use std::collections::{RingBuf, Deque};
///
/// let mut queue = RingBuf::new();
/// queue.push_back(1i);
/// queue.push_back(2i);
/// queue.push_back(3i);
///
/// // Will print 1, 2, 3
/// while !queue.is_empty() {
/// let x = queue.pop_front().unwrap();
/// println!("{}", x);
/// }
/// ```
///
/// And of course we can mix and match:
///
/// ```
/// use std::collections::{DList, Deque};
///
/// let mut deque = DList::new();
///
/// // Init deque with 1, 2, 3, 4
/// deque.push_front(2i);
/// deque.push_front(1i);
/// deque.push_back(3i);
/// deque.push_back(4i);
///
/// // Will print (1, 4) and (2, 3)
/// while !deque.is_empty() {
/// let f = deque.pop_front().unwrap();
/// let b = deque.pop_back().unwrap();
/// println!("{}", (f, b));
/// }
/// ```
pub
trait
Deque
<
T
>
:
Mutable
{
/// Provide a reference to the front element, or None if the sequence is
/// empty
/// Provide a reference to the front element, or `None` if the sequence is.
/// empty.
///
/// # Example
///
/// ```
/// use std::collections::{RingBuf, Deque};
///
/// let mut d = RingBuf::new();
/// assert_eq!(d.front(), None);
///
/// d.push_back(1i);
/// d.push_back(2i);
/// assert_eq!(d.front(), Some(&1i));
/// ```
fn
front
<
'a
>
(
&
'a
self
)
->
Option
<&
'a
T
>
;
/// Provide a mutable reference to the front element, or None if the
/// sequence is empty
/// Provide a mutable reference to the front element, or `None` if the
/// sequence is empty.
///
/// # Example
///
/// ```
/// use std::collections::{RingBuf, Deque};
///
/// let mut d = RingBuf::new();
/// assert_eq!(d.front_mut(), None);
///
/// d.push_back(1i);
/// d.push_back(2i);
/// match d.front_mut() {
/// Some(x) => *x = 9i,
/// None => (),
/// }
/// assert_eq!(d.front(), Some(&9i));
/// ```
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
/// empty.
///
/// # Example
///
/// ```
/// use std::collections::{DList, Deque};
///
/// let mut d = DList::new();
/// assert_eq!(d.back(), None);
///
/// d.push_back(1i);
/// d.push_back(2i);
/// assert_eq!(d.back(), Some(&2i));
/// ```
fn
back
<
'a
>
(
&
'a
self
)
->
Option
<&
'a
T
>
;
/// Provide a mutable reference to the back element, or None if the sequence
/// is empty
/// is empty.
///
/// # Example
///
/// ```
/// use std::collections::{DList, Deque};
///
/// let mut d = DList::new();
/// assert_eq!(d.back(), None);
///
/// d.push_back(1i);
/// d.push_back(2i);
/// match d.back_mut() {
/// Some(x) => *x = 9i,
/// None => (),
/// }
/// assert_eq!(d.back(), Some(&9i));
/// ```
fn
back_mut
<
'a
>
(
&
'a
mut
self
)
->
Option
<&
'a
mut
T
>
;
/// Insert an element first in the sequence
/// Insert an element first in the sequence.
///
/// # Example
///
/// ```
/// use std::collections::{DList, Deque};
///
/// let mut d = DList::new();
/// d.push_front(1i);
/// d.push_front(2i);
/// assert_eq!(d.front(), Some(&2i));
fn
push_front
(
&
mut
self
,
elt
:
T
);
/// Insert an element last in the sequence
/// Insert an element last in the sequence.
///
/// # Example
///
/// ```
/// use std::collections::{DList, Deque};
///
/// let mut d = DList::new();
/// d.push_back(1i);
/// d.push_back(2i);
/// assert_eq!(d.front(), Some(&1i));
fn
push_back
(
&
mut
self
,
elt
:
T
);
/// Remove the last element and return it, or None if the sequence is empty
/// Remove the last element and return it, or None if the sequence is empty.
///
/// # Example
///
/// ```
/// use std::collections::{RingBuf, Deque};
///
/// let mut d = RingBuf::new();
/// d.push_back(1i);
/// d.push_back(2i);
///
/// assert_eq!(d.pop_back(), Some(2i));
/// assert_eq!(d.pop_back(), Some(1i));
/// assert_eq!(d.pop_back(), None);
fn
pop_back
(
&
mut
self
)
->
Option
<
T
>
;
/// Remove the first element and return it, or None if the sequence is empty
/// Remove the first element and return it, or None if the sequence is empty.
///
/// # Example
///
/// ```
/// use std::collections::{RingBuf, Deque};
///
/// let mut d = RingBuf::new();
/// d.push_back(1i);
/// d.push_back(2i);
///
/// assert_eq!(d.pop_front(), Some(1i));
/// assert_eq!(d.pop_front(), Some(2i));
/// assert_eq!(d.pop_front(), None);
fn
pop_front
(
&
mut
self
)
->
Option
<
T
>
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录