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

run examples code in my lib error #244

Open
CppXL opened this issue Aug 20, 2022 · 5 comments
Open

run examples code in my lib error #244

CppXL opened this issue Aug 20, 2022 · 5 comments
Assignees
Labels

Comments

@CppXL
Copy link

CppXL commented Aug 20, 2022

my rust env

  • windows 10
  • cargo -V
    cargo 1.62.1 (a748cf5a3 2022-06-08)
    

I have a rust library which create by cargo new circ --bin
I try to copy irc/examples/simple_plaintext.rs source code to circ/src/main.rs

when I try to build it with cargo build, cargo give three errors

Compiling circ v0.1.0 (F:\code\rust\virc\circ)
error[E0433]: failed to resolve: could not find `main` in `tokio`
 --> src\main.rs:7:10
  |
7 | #[tokio::main]
  |          ^^^^ could not find `main` in `tokio`

error[E0560]: struct `irc::client::data::Config` has no field named `use_tls`
  --> src\main.rs:13:9
   |
13 |         use_tls: Some(false),
   |         ^^^^^^^ `irc::client::data::Config` does not have this field
   |
   = note: available fields are: `owners`, `nickname`, `nick_password`, `alt_nicks`, `username` ... and 24 others

error[E0752]: `main` function is not allowed to be `async`
 --> src\main.rs:8:1
  |
8 | async fn main() -> irc::error::Result<()> {
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `main` function is not allowed to be `async`

Some errors have detailed explanations: E0433, E0560, E0752.
For more information about an error, try `rustc --explain E0433`.
error: could not compile `circ` due to 3 previous errors

This is src/main.rs

extern crate futures;
extern crate irc;

use futures::prelude::*;
use irc::client::prelude::*;

#[tokio::main]
async fn main() -> irc::error::Result<()> {
    let config = Config {
        nickname: Some("pickles".to_owned()),
        server: Some("chat.freenode.net".to_owned()),
        channels: vec!["#rust-spam".to_owned()],
        use_tls: Some(false),
        ..Default::default()
    };

    let mut client = Client::from_config(config).await?;
    client.identify()?;

    let mut stream = client.stream()?;
    let sender = client.sender();

    while let Some(message) = stream.next().await.transpose()? {
        print!("{}", message);

        match message.command {
            Command::PRIVMSG(ref target, ref msg) => {
                if msg.contains(client.current_nickname()) {
                    sender.send_privmsg(target, "Hi!")?;
                }
            }
            _ => (),
        }
    }

    Ok(())
}

This is Cargo.toml

[package]
name = "circ"
version = "0.1.0"
edition = "2021"

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


[dependencies]

irc-proto = { version = "0.14.0" }


# Feature - TLS
irc = { git = "https://github.com/aatxe/irc", branch = "0.14", features = [
    "ctcp",
    "toml",
] }

native-tls = { version = "0.2.0", optional = true }
tokio-rustls = { version = "0.22.0", features = [
    "dangerous_configuration",
], optional = true }
tokio-native-tls = { version = "0.3.0", optional = true }
tokio = { version = "1.0.0", features = ["net", "time", "sync"] }
tokio-stream = "0.1.0"
tokio-util = { version = "0.6.0", features = ["codec"] }
futures = "0.3.0"
@CppXL
Copy link
Author

CppXL commented Aug 20, 2022

I just can only build examples code in git clone https://github.com/aatxe/irc.git directory

@aatxe
Copy link
Owner

aatxe commented Aug 22, 2022

It looks like the #[tokio::main] macro is locked behind a feature now, so you'd need to add rt and macros to the feature list for the tokio crate.

@aatxe aatxe added the question label Aug 22, 2022
@aatxe aatxe self-assigned this Aug 22, 2022
@CppXL
Copy link
Author

CppXL commented Aug 23, 2022

It looks like the #[tokio::main] macro is locked behind a feature now, so you'd need to add rt and macros to the feature list for the tokio crate.

thanks for you response, now I can compile fine, but a panic is triggered in the tokio library, I will continue to investigate how this error is generated

@GTP95
Copy link

GTP95 commented Apr 6, 2023

It looks like the #[tokio::main] macro is locked behind a feature now, so you'd need to add rt and macros to the feature list for the tokio crate.

Sorry, I'm new to Rust, how do I do this?

@8573
Copy link

8573 commented May 7, 2023

@GTP95:

tokio = { version = "1.28.0", features = ["rt", "macros"] }

See https://doc.rust-lang.org/stable/cargo/reference/features.html#dependency-features.

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

No branches or pull requests

4 participants