Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust may complain when using embedded-nal trait objects directly #36

Closed
ryan-summers opened this issue Nov 25, 2022 · 2 comments · Fixed by #43
Closed

Rust may complain when using embedded-nal trait objects directly #36

ryan-summers opened this issue Nov 25, 2022 · 2 comments · Fixed by #43

Comments

@ryan-summers
Copy link
Collaborator

When following the example on the README, there's an issue with the TCP example.

Specifically, the compiler will complain about the connect() function being private. This arises because the TcpSocket exposes two connect() functions - one as a private function, and one as a public trait method of TcpClientStack.

Rust's method call ordering specifies that the private function is found first, which results in the compiler thinking that incorrect arguments and invalid private scope is identified.

Users can work around this by explicitly casting the socket to a trait object (See https://doc.rust-lang.org/reference/expressions/call-expr.html#disambiguating-function-calls), but this is incredibly not user-friendly.

We should rename all of the private methods of the sockets to not conflict with the trait implementations to avoid this confusion.

@andresv
Copy link

andresv commented Mar 23, 2023

I was pulling my hair out figuring out what is wrong with the example.

use embedded_nal::{IpAddr, Ipv4Addr, SocketAddr, TcpClientStack};
...

let mut socket = device.socket().unwrap();
TcpClientStack::connect(&mut device, &mut socket, SocketAddr::new(IpAddr::V4(Ipv4Addr::new(192, 168, 86, 38)), 8000)).unwrap();

@andresv
Copy link

andresv commented Mar 23, 2023

Wait a sec this was wrong. It should be like this:

let mut socket = device.socket().unwrap();
device.connect(&mut socket, SocketAddr::new(IpAddr::V4(Ipv4Addr::new(192, 168, 86, 38)), 8000)).unwrap();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants