當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Rust LinkedList.clear用法及代碼示例

本文簡要介紹rust語言中 alloc::collections::linked_list::LinkedList.clear 的用法。

用法

pub fn clear(&mut self)

LinkedList 中刪除所有元素。

此操作應在 O(n) 時間內計算。

例子

use std::collections::LinkedList;

let mut dl = LinkedList::new();

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

dl.clear();
assert_eq!(dl.len(), 0);
assert_eq!(dl.front(), None);

相關用法


注:本文由純淨天空篩選整理自rust-lang.org大神的英文原創作品 alloc::collections::linked_list::LinkedList.clear。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。