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

Method push

publication/code/chapter04/list_stack.rs:51–56  ·  view source on GitHub ↗

take 取出 top 中节点,留下空位,可以回填

(&mut self, val: T)

Source from the content-addressed store, hash-verified

49
50 // take 取出 top 中节点,留下空位,可以回填
51 fn push(&mut self, val: T) {
52 let mut node = Node::new(val);
53 node.next = self.top.take();
54 self.top = Some(Box::new(node));
55 self.size += 1;
56 }
57
58 fn pop(&mut self) -> Option<T> {
59 self.top.take().map(|node| {

Callers 2

basicFunction · 0.45
iterFunction · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected