mirror of
https://github.com/eunomia-bpf/bpf-developer-tutorial.git
synced 2026-04-02 02:01:26 +08:00
Deploying to gh-pages from @ eunomia-bpf/bpf-developer-tutorial@4671af2739 🚀
This commit is contained in:
2
37-uprobe-rust/args/.gitignore
vendored
Normal file
2
37-uprobe-rust/args/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
target
|
||||
Cargo.lock
|
||||
8
37-uprobe-rust/args/Cargo.toml
Normal file
8
37-uprobe-rust/args/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "helloworld"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
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