当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Rust LinkedList.front用法及代码示例


本文简要介绍rust语言中 alloc::collections::linked_list::LinkedList.front 的用法。

用法

pub fn front(&self) -> Option<&T>

提供对前面元素的引用,如果列表为空,则提供 None

此操作应在 O(1) 时间内计算。

例子

use std::collections::LinkedList;

let mut dl = LinkedList::new();
assert_eq!(dl.front(), None);

dl.push_front(1);
assert_eq!(dl.front(), Some(&1));

相关用法


注:本文由纯净天空筛选整理自rust-lang.org大神的英文原创作品 alloc::collections::linked_list::LinkedList.front。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。