MCPcopy Create free account
hub / github.com/QMHTMY/RustBook / push

Method push

publication/code/chapter04/linked_list.rs:40–47  ·  view source on GitHub ↗

新节点总是加到头部,

(&mut self, elem: T)

Source from the content-addressed store, hash-verified

38
39 // 新节点总是加到头部,
40 fn push(&mut self, elem: T) {
41 let node = Box::new(Node {
42 elem: elem,
43 next: self.head.take(),
44 });
45 self.head = Some(node);
46 self.size += 1;
47 }
48
49 // take 会取出数据留下空位
50 fn pop(&mut self) -> Option<T> {

Callers 4

basic_testFunction · 0.45
into_iter_testFunction · 0.45
iter_testFunction · 0.45
iter_mut_testFunction · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected