project-chip / rs-matter

Rust implementation of the Matter protocol. Status: Experimental
Apache License 2.0
314 stars 45 forks source link

Fix compiler errors about lifetime #83

Closed markus-becker-tridonic-com closed 1 year ago

markus-becker-tridonic-com commented 1 year ago

With

rustc --version
rustc 1.68.2 (9eb3afe9e 2023-03-27)
cargo --version
cargo 1.68.2 (6feb7c9cf 2023-03-26)

I was getting the following errors:

   Compiling rs-matter v0.1.0 (/Users/markusbecker/src/matter-rs/rs-matter)
error[E0310]: the parameter type `D` may not live long enough
   --> rs-matter/src/mdns/builtin.rs:131:5
    |
131 | /     {
132 | |         let mut udp = crate::transport::udp::UdpListener::new(
133 | |             stack,
134 | |             crate::transport::network::SocketAddr::new(IpAddr::V6(Ipv6Addr::UNSPECIFIED), PORT),
...   |
201 | |             .unwrap()
202 | |     }
    | |_____^ ...so that the type `D` will meet its required lifetime bounds
    |
help: consider adding an explicit lifetime bound...
    |
130 |         D: crate::transport::network::NetworkStackDriver + 'static,
    |                                                          +++++++++

error[E0310]: the parameter type `D` may not live long enough
   --> rs-matter/src/transport/core.rs:134:5
    |
134 | /     {
135 | |         let udp = crate::transport::udp::UdpListener::new(
136 | |             stack,
137 | |             crate::transport::network::SocketAddr::new(
...   |
200 | |             .unwrap()
201 | |     }
    | |_____^ ...so that the type `D` will meet its required lifetime bounds
    |
help: consider adding an explicit lifetime bound...
    |
132 |         D: crate::transport::network::NetworkStackDriver + 'static,
    |                                                          +++++++++

For more information about this error, try `rustc --explain E0310`.

This commit applies those recommendations.

ivmarkov commented 1 year ago

@markus-becker-tridonic-com:

I don't see these errors. (I've tried latest stable - 1.71 and latest nightly - 1.73).

What compiler version are you using?

ivmarkov commented 1 year ago

Ah, it is 1.68.2 - I should read more carefully!

How about upgrading to 1.71?

markus-becker-tridonic-com commented 1 year ago

Ah, it is 1.68.2 - I should read more carefully!

How about upgrading to 1.71?

Ah, right. Interesting that lifetimes are not required anymore on 1.71.