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

Tokio module 'runtime' is private #191

Closed
ShayBox opened this issue May 21, 2023 · 12 comments · Fixed by #192
Closed

Tokio module 'runtime' is private #191

ShayBox opened this issue May 21, 2023 · 12 comments · Fixed by #192
Labels

Comments

@ShayBox
Copy link

ShayBox commented May 21, 2023

image

error[E0412]: cannot find type `Runtime` in `tokio::runtime`
  --> C:\Users\Admin\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-modbus-0.8.0\src\client\sync\mod.rs:26:31
   |
26 |     runtime: &tokio::runtime::Runtime,
   |                               ^^^^^^^ not found in `tokio::runtime`

error[E0412]: cannot find type `Runtime` in `tokio::runtime`
  --> C:\Users\Admin\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-modbus-0.8.0\src\client\sync\mod.rs:75:30
   |
75 |     runtime: tokio::runtime::Runtime,
   |                              ^^^^^^^ not found in `tokio::runtime`

error[E0603]: module `runtime` is private
   --> C:\Users\Admin\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-modbus-0.8.0\src\client\sync\mod.rs:26:22
    |
26  |     runtime: &tokio::runtime::Runtime,
    |                      ^^^^^^^ private module
    |
note: the module `runtime` is defined here
   --> C:\Users\Admin\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-1.28.1\src\lib.rs:525:5
    |
525 |     pub(crate) mod runtime;
    |     ^^^^^^^^^^^^^^^^^^^^^^

error[E0603]: module `runtime` is private
   --> C:\Users\Admin\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-modbus-0.8.0\src\client\sync\mod.rs:75:21
    |                     ^^^^^^^ private module
    |
note: the module `runtime` is defined here
   --> C:\Users\Admin\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-1.28.1\src\lib.rs:525:5
    |
525 |     pub(crate) mod runtime;
    |     ^^^^^^^^^^^^^^^^^^^^^^

Some errors have detailed explanations: E0412, E0603.
For more information about an error, try `rustc --explain E0412`.
error: could not compile `tokio-modbus` due to 4 previous errors
warning: build failed, waiting for other jobs to finish...
@ShayBox
Copy link
Author

ShayBox commented May 21, 2023

This appears to be caused by this https://github.com/tokio-rs/tokio/blame/master/tokio/src/lib.rs#L536-L541

@flosse
Copy link
Member

flosse commented May 21, 2023

... so it's not related to tokio-modbus, right?

@ShayBox
Copy link
Author

ShayBox commented May 21, 2023

This is related to tokio-modbus, the error comes from it trying to access the runtime tokio module without the cfg_rt! (I don't know what that macro expands to, likely a cfg feature flag?)

@flosse
Copy link
Member

flosse commented May 21, 2023

hm... I tried to compile some examples and could not reproduce this error. Could you provide some more info to reproduce it?

@ShayBox
Copy link
Author

ShayBox commented May 21, 2023

Cargo.toml

[package]
name = "test"
version = "0.0.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
tokio-modbus = { version = "0.8.0", default-features = false, features = ["rtu-sync"] }
tokio-serial = "5.4.4"

src/main.rs examples/rtu-client-sync.rs

// SPDX-FileCopyrightText: Copyright (c) 2017-2023 slowtec GmbH <post@slowtec.de>
// SPDX-License-Identifier: MIT OR Apache-2.0

//! Synchronous RTU client example

fn main() -> Result<(), Box<dyn std::error::Error>> {
    use tokio_modbus::prelude::*;

    let tty_path = "/dev/ttyUSB0";
    let slave = Slave(0x17);

    let builder = tokio_serial::new(tty_path, 19200);

    let mut ctx = sync::rtu::connect_slave(&builder, slave)?;
    println!("Reading a sensor value");
    let rsp = ctx.read_holding_registers(0x082B, 2)?;
    println!("Sensor value is: {rsp:?}");

    Ok(())
}

@ShayBox
Copy link
Author

ShayBox commented May 21, 2023

It appears to be because of default-features = false, it's been a while since I touched my project and I just updated it, but this comment implies it's still an intended use-case, probably one of the optional dependencies from a different feature is explicitly required.

@flosse
Copy link
Member

flosse commented May 21, 2023

I'm so sorry, I'm still not able to produce the error, even if I disable the default features 🤔
This is what works fine on my machine:

cargo check --no-default-features --features rtu-sync --example rtu-client-sync

@ShayBox
Copy link
Author

ShayBox commented May 21, 2023

Yes that command works if I clone tokio-modbus and run it within, this only happens in a new project with tokio-modbus as a dependency

@ShayBox
Copy link
Author

ShayBox commented May 21, 2023

Here's my test project if you like, it's just the above two files Test.zip
$ cargo build

@flosse
Copy link
Member

flosse commented May 21, 2023

I see...you're right!

@flosse flosse added the bug label May 21, 2023
@flosse
Copy link
Member

flosse commented May 21, 2023

Could you check if #192 solves the problem?

@ShayBox
Copy link
Author

ShayBox commented May 21, 2023

That does fix it 👍

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

Successfully merging a pull request may close this issue.

2 participants