mirror of
https://github.com/eunomia-bpf/bpf-developer-tutorial.git
synced 2026-05-07 22:21:55 +08:00
Deploying to gh-pages from @ eunomia-bpf/bpf-developer-tutorial@4671af2739 🚀
This commit is contained in:
23
37-uprobe-rust/args/src/main.rs
Normal file
23
37-uprobe-rust/args/src/main.rs
Normal file
@@ -0,0 +1,23 @@
|
||||
use std::env;
|
||||
|
||||
pub fn hello(i: i32, len: usize) -> i32 {
|
||||
println!("Hello, world! {} in {}", i, len);
|
||||
i + len as i32
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
|
||||
// Skip the first argument, which is the path to the binary, and iterate over the rest
|
||||
for arg in args.iter().skip(1) {
|
||||
match arg.parse::<i32>() {
|
||||
Ok(i) => {
|
||||
let ret = hello(i, args.len());
|
||||
println!("return value: {}", ret);
|
||||
}
|
||||
Err(_) => {
|
||||
eprintln!("Error: Argument '{}' is not a valid integer", arg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user