aya-rs / book

The Aya Book is an introductory book about using the Rust Programming Language and Aya library to build extended Berkley Packet Filter (eBPF) programs.
https://aya-rs.dev/book/
Apache License 2.0
82 stars 60 forks source link

examples/myapp-02 'cargo build' fails #20

Closed dmitris closed 2 years ago

dmitris commented 2 years ago

Running cargo build in examples/myapp-02 fails:

   Compiling myapp v0.1.0 (/home/dmitris
![Screenshot 2022-01-14 at 13 18 35](https://user-images.githubusercontent.com/31205/149514426-0c779154-177b-4f14-baf3-d3d5d1493c22.png)
![Screenshot 2022-01-14 at 13 18 35](https://user-images.githubusercontent.com/31205/149514485-be4ff808-d901-4ee0-8b87-5d73df53f785.png)
/dev/hack/gh/aya-rs/book/examples/myapp-02/myapp)
error[E0277]: the `?` operator can only be used on `Result`s, not `Option`s, in an async block that returns `Result`
  --> myapp/src/main.rs:31:49
   |
18 |   async fn main() -> Result<(), anyhow::Error> {
   |  ______________________________________________-
19 | |     let path = match env::args().nth(1) {
20 | |         Some(iface) => iface,
21 | |         None => panic!("not path provided"),
...  |
31 | |     let probe: &mut Xdp = bpf.program_mut("xdp")?.try_into()?;
   | |                                                 ^ use `.ok_or(...)?` to provide an error compatible with `Result<(), anyhow::Error>`
...  |
60 | |     Ok::<_, anyhow::Error>(())
61 | | }
   | |_- this function returns a `Result`
   |
   = help: the trait `FromResidual<Option<Infallible>>` is not implemented for `Result<(), anyhow::Error>`

For more information about this error, try `rustc --explain E0277`.
error: could not compile `myapp` due to previous error
dmitris commented 2 years ago

Screenshot 2022-01-14 at 13 18 35