Code
Hub
Workspaces
Following
Trending
Connect
MCP
copy
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
3
use std::borrow::Cow;
4
5
fn 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
14
fn main() {
15
// 只读,不写,没有发生复制操作
Callers
1
main
Function · 0.85
Calls
1
len
Method · 0.45
Tested by
no test coverage detected