0
votes

I'm very new to Rust and willing to make some Linux service for Orange Pi Zero in Actix-web, that will act as a "gateway" to other network device (some dumb Chinese network relay with 4 inputs and 4 ouputs which is controlled by AT commands via TCP or UDP) and will asynchronously poll that device and convert its output as a constantly refreshed web page via WebSocket. I want to make 2 different actors, the first one should be a TCP client actor that polls a relay via run_interval(), makes a network request with appropriate AT command, reads a response and sends a message to WebSocket actor that will push messages with input states to web page. I successfully implemented the WebSocket one and trying to implement another actor using TcpStream, FramedWrite and LinesCodec. My TCP actor looks like this:

struct TcpClientActor {
    framed: actix::io::FramedWrite<
        String,
        WriteHalf<TcpStream>,
        LinesCodec,
    >,
}

I also have a bunch of another trait implementations for it, that are compiled without any issues, but stuck on struct itself, the compiler complains with the following error:

the trait `tokio::io::async_write::AsyncWrite` is not implemented for `tokio::io::split::WriteHalf<tokio::net::tcp::stream::TcpStream>`

I checked the Actix sources and found that AsyncWrite is already implemented for WriteHalf, as well as for TcpStream, but can't get it compiled without errors.

This is my [dependencies] section of Cargo.toml:

[dependencies]
# sysfs_gpio = "0.5"
actix = "0.10"
actix-codec = "0.3"
actix-web = "3"
actix-web-actors = "3"
actix-files = "0.3"
env_logger = "0.7"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
json = "0.12"
#mio = "0.7"
tokio = { version = "0.3.1", features = ["full", "tracing"] }
tokio-util = "0.3.1"

Additionally, I want to wrap the first actor with Supervisor to handle the disconnects and other network issues. Please provide any examples.

Will appreciate any help.

1

1 Answers

1
votes

You have probably hit an unfortunately confusing case of conflicting dependencies.

The actix crate has a dependency on tokio 0.2.6. However, you've listed your dependency as tokio 0.3.1. Cargo considers 0.2.x and 0.3.x to be incompatible and will therefore include two versions of tokio in your project. The cause of the confusing error message is you're using a 0.3 version of WriteHalf but the actix FramedWrite is execting something implementing the 0.2 version of AsyncWrite.

The fix is probably to downgrade your version of tokio to 0.2

See also: Why is a trait not implemented for a type that clearly has it implemented?