interprocess
interprocess copied to clipboard
Errors: could not find `tokio` in `udsocket` & incorrect number of function parameters
Getting the following error:
error: the main function cannot accept arguments
--> src/server.rs:17:10
|
17 | async fn main(notify: Sender<()>) -> Result<()> {
| ^^^^
error[E0432]: unresolved import `interprocess::os::unix::udsocket::tokio`
--> src/server.rs:9:39
|
9 | use interprocess::os::unix::udsocket::tokio::{UdStream, UdStreamListener};
| ^^^^^ could not find `tokio` in `udsocket`
error[E0580]: `main` function has wrong type
--> src/server.rs:17:7
|
17 | async fn main(notify: Sender<()>) -> Result<()> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ incorrect number of function parameters
|
= note: expected fn pointer `fn() -> Result<_, _>`
found fn pointer `fn(tokio::sync::oneshot::Sender<()>) -> Result<_, _>`
I'm guessing it's because I'm not adding include!("../../example_main.rs");
Can you please provide an example that doesn't involve include!("../../example_main.rs");
?
The examples as they are written now aren't meant to demonstrate how you'd write a trivial async program, but rather how to use the crate's interface. This means that the signatures of main()
and the imports aren't really supposed to be looked at; furthermore, they won't work if copypasted without modification. Some mistakes you've made right out of the gate:
- The compiler is correctly telling you that
main()
doesn't accept arguments. It does in the example becauseexample_main.rs
provides a wrappermain()
function that provides synchronization, stalling the client until the server fully boots up; themain()
functions you see in the examples aren't the real entry points to the client and server programs. A full-fledged program would employ a different kind of synchronization – or perhaps none at all, depending on what you want the code to do if the client is started at a time when the server isn't running – and implement it within its ownmain()
. - Because you're not supposed to use the
example_main.rs
wrapper, yourmain()
function needs to be annotated with#[tokio::main]
, else it won't be allowed to beasync
. Alternatively, it could start its own Tokio runtime manually and run anasync
function of your choosing. - Unrelated to the peculiarities of the example, you haven't enabled the
tokio_support
feature flag as described in the top-level readme, which means that the Tokio dependency isn't included in your build ofinterprocess
at all. To fix this, apply the following change to yourCargo.toml
:- interprocess = "1.2.1" + interprocess = { version = "1.2.1", features = ["tokio_support"] }
The reason the examples are the way they are is that they're the remnants of a failed attempt to unify examples and tests. I'm planning to move them back to the Rustdoc documentation where they used to be in an older version, so I'll consider this unsolved for now and will close the issue when I do.
As the examples now reside entirely within Rustdoc, this issue is no longer applicable, and, I assume, is solved.