Rust noobie help, cant compile error code 22 invalid argument

Hi im new to rust, I wa asked to do a proect for work using it and am kind of clueless about it. Ive been able to install rust on a raspberry pi and create a project using cargo. When i build it I just get a warning but when I try to run it i get an error with code 22 invalid argument. Can anyone help please ? the code im trying to run is here https://github.com/rust-embedded/rust-sysfs-gpio, its the example on that page. Im trying to run this on an raspberry pi.

Maybe the problem is at this point

...
let my_led = Pin::new(127); // number depends on chip, etc.
...

But I can't be sure

The error said something about unwrap, it's on my work computer so can't check now but will post the whole thing tomorrow when I get to work

after using cargo run the error I get is. thread "main" panicked at "called "Result::unwrap()" on an "Err" value: Io(error { repr: Os { code:22, message: "invalid argument"} })", /checkout/src/libcore/result.rs:860. note: Run with "Rust_Backtrace=1" for a backtrace.

You should try to get a backtrace. The line number currently shows it crashing inside libcore/result.rs which is not useful information. You want to find the line where it crashes in your source code.

I found some other code which was based on the one I was using which kind of works. When I run it gives me permission denied error i then run with sudo which gives folder not found error but I am then able to run it.

The reason you get a permission error without using sudo is because you need to be root in order to interact with hardware.

When you run it as sudo, it'll return a Result because you can either get back an error or the pin, depending on if opening the pin was successful. Using the unwrap() method then tries to extract the value, otherwise if there's an error your program will blow up (printing the panic message and optionally giving you a backtrack). unwrap() is mainly used when you are prototyping and don't care about handling errors just yet.

If it's saying invalid argument chances are the pin you asked for doesn't exist. You may want to double check that 127 is the correct pin to use for your device.