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

Method enqueue

code/chapter03/queue.rs:19–26  ·  view source on GitHub ↗

判断是否有剩余空间、有则数据加入队列

(&mut self, val: T)

Source from the content-addressed store, hash-verified

17
18 // 判断是否有剩余空间、有则数据加入队列
19 fn enqueue(&mut self, val: T) -> Result<(), String> {
20 if self.size() == self.cap {
21 return Err("No space available".to_string());
22 }
23 self.data.insert(0, val);
24
25 Ok(())
26 }
27
28 // 数据出队
29 fn dequeue(&mut self) -> Option<T> {

Callers 1

mainFunction · 0.45

Calls 3

sizeMethod · 0.45
to_stringMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected