Can't compile to exe file
KonyD opened this issue · comments
When i try to compile my code its gives me this 2 errors.
error[E0432]: unresolved import `owo_colors`
--> src/main.rs:1:5
|
1 | use owo_colors::OwoColorize;
| ^^^^^^^^^^ maybe a missing crate `owo_colors`?
error[E0599]: no method named `on_green` found for type `{integer}` in the current scope
--> src/main.rs:15:57
|
15 | ...7878.on_green());
| ^^^^^^^^ method not found in `{integer}`
You need to add owo-colors to your Cargo.toml
Try running the following command:
cargo add owo-colors
Or manually adding the following line to Cargo.toml:
owo-colors = "3"
If you have any further issues let me know :)
ok i'll try thanks
it didn't work
could you provide more info on how it didn't work?
I'm not sure why its not working. When i run the code its working but when i try compiling to exe file its saying there is no crate named owo_colors.
main.rs file
use owo_colors::OwoColorize;
use std::{env, fs};
use std::net::{TcpListener, TcpStream};
use std::io::prelude::*;
fn main() {
let args: Vec<String> = env::args().collect();
if args[1] == "run" {
let listener:TcpListener = TcpListener::bind("127.0.0.1:7878").unwrap();
for stream in listener.incoming() {
let stream: TcpStream = stream.unwrap();
println!("server created on port: {}", 7878.on_green());
handle_connection(stream);
}
}
}
fn handle_connection(mut stream: TcpStream) {
let mut buffer: [u8; 1024] = [0; 1024];
stream.read(&mut buffer).unwrap();
let contents: String = fs::read_to_string("index.html").unwrap();
let response: String = format!(
"HTTP/1.1 200 OK\r\nContent-Length: {}\r\n\r\n{}",
contents.len(),
contents
);
stream.write(response.as_bytes()).unwrap();
stream.flush().unwrap();
}
cargo toml file
[package]
name = "fantasy_console"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
owo-colors = "3.5.0"
What command are you running to compile to an exe? Is there a chance you're using rustc directly rather than building via cargo?
I also went ahead and ran is. First time around, cargo didn't try to download the library initially. After restarting my IDE and waiting for the rust-analizer to finish, It compiled successfully. Not sure if this will help... but maybe a good old fashion restart could work?