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

Function abs_all

publication/code/chapter01/more_cow_usage.rs:5–12  ·  view source on GitHub ↗
(input: &mut Cow<[i32]>)

Source from the content-addressed store, hash-verified

3use std::borrow::Cow;
4
5fn abs_all(input: &mut Cow<[i32]>) {
6 for i in 0..input.len() {
7 let v = input[i];
8 if v < 0 {
9 input.to_mut()[i] = -v;
10 }
11 }
12}
13
14fn main() {
15 // 只读,不写,没有发生复制操作

Callers 1

mainFunction · 0.85

Calls 1

lenMethod · 0.45

Tested by

no test coverage detected