Code very similar to the example does not work
Blayung opened this issue · 6 comments
I've actually modified it a bit, but it still seems weird:
error[E0282]: type annotations needed for `NodeEvent<'_, S>`
--> src/client.rs:28:72
|
28 | ... let mut network_thread = network_listener.for_each_async(move |node_event| match node_event {
| ^^^^^^^^^^
|
help: consider giving this closure parameter an explicit type, where the type for type parameter `S` is specified
|
28 | let mut network_thread = network_listener.for_each_async(move |node_event: NodeEvent<'_, S>| match node_event {
|
It seems simple to fix, but it results in an infinite loop of type annotations required:
error[E0107]: missing generics for enum `NodeEvent`
--> src/client.rs:28:130
|
28 | let mut network_thread = network_listener.for_each_async(move |node_event: message_io::node::NodeEvent<message_io::node::NodeEvent>| match node_event {
| ^^^^^^^^^ expected 1 generic argument
|
note: enum defined here, with 1 generic parameter: `S`
--> /home/wojtek/.cargo/registry/src/index.crates.io-6f17d22bba15001f/message-io-0.18.1/src/node.rs:18:10
|
18 | pub enum NodeEvent<'a, S> {
| ^^^^^^^^^ -
help: add missing generic argument
|
28 | let mut network_thread = network_listener.for_each_async(move |node_event: message_io::node::NodeEvent<message_io::node::NodeEvent<S>>| match node_event {
|
While the example doesn't contain them at all!
Hi, how are you compiling them? a simple cargo test
for me compile the example without errors
What is your rust version?
My rustc version: rustc 1.74.1 (a28077b28 2023-12-04)
And I'm not compiling your examples, I'm compiling my modified code - your examples indeed work as expected. I don't know what's wrong with mine though.
I'm doing this:
let (network_handler, network_listener) = message_io::node::split();
let (server, _) = network_handler.network().connect(message_io::network::Transport::FramedTcp, SERVER_ADDRESS).unwrap();
let mut network_thread = network_listener.for_each_async(move |node_event| match node_event {
message_io::node::NodeEvent::Network(net_event) => match net_event {
message_io::network::NetEvent::Connected(_, is_ok) => {
assert!(is_ok);
},
message_io::network::NetEvent::Message(_, data) => {
},
message_io::network::NetEvent::Disconnected(_) => {},
message_io::network::NetEvent::Accepted(_, _) => unreachable!()
},
message_io::node::NodeEvent::Signal(_) => {}
});
I've updated rust and now it returns a diffrent, but very similar error:
error[E0283]: type annotations needed for `NodeEvent<'_, S>`
--> src/client.rs:29:72
|
26 | ...work_listener) = message_io::node::split();
| ------------------------- type must be known at this point
...
29 | ...network_listener.for_each_async(move |node_event| match node_event {
| ^^^^^^^^^^
|
= note: cannot satisfy `_: Send`
note: required by a bound in `message_io::node::split`
--> /home/wojtek/.cargo/registry/src/index.crates.io-6f17d22bba15001f/message-io-0.18.1/src/node.rs:180:17
|
180 | pub fn split<S: Send>() -> (NodeHandler<S>, NodeListener<S>) {
| ^^^^ required by this bound in `split`
help: consider giving this closure parameter an explicit type, where the type for type parameter `S` is specified
|
29 | let mut network_thread = network_listener.for_each_async(move |node_event: NodeEvent<'_, S>| match node_event {
| ++++++++++++++++++
You need to specify the signal type. You can see this in the examples, i.e, in the README example it's as follows (for an empty signal ()
type):
let (handler, listener) = node::split::<()>();
Please note that I can give support to the library itself. But I do not for external code.
Okay! It fixed the issue, it was just my inattention. Sorry for bothering you.