6 个版本
0.1.6 | 2023年11月7日 |
---|---|
0.1.5 | 2023年11月7日 |
#1 in #ez
每月下载 22 次
7KB
118 行
ez-rust
使用 Rust 的实用函数非常简单
安装
使用 cargo
cargo add ez-rust
或者手动通过将 ez-rust = "0.1.6"
添加到 Cargo.toml
文件的依赖项中
文档
IO
输入
要使用 ez_rust::io
模块获取输入,请使用 get_input()
函数
示例
use ez_rust::io
fn main() {
let name: String = io::get_input("Whats your name?");
println!("Hello {name}!");
}
颜色
要美化终端输出,我们使用包含易于使用的美化函数的 ez_rust::io::Colors
结构体
示例
use ez_rust::io::Colors
fn main() {
println!(
"Normal {} Danger! {} Blue {} Green",
Colors::bg_red(),
Colors::fg_blue(),
Colors::fg_green()
);
}
以下是所有背景颜色和前景颜色的列表
背景 | 前景 |
---|---|
bg_red | fg_red |
bg_yellow | fg_yellow |
bg_green | fg_green |
bg_blue | fg_blue |
bg_magenta | fg_magenta |
bg_white | fg_white |
bg_black | fg_black |
bg_reset | fg_reset |
bg_reset() 和 fg_reset() 分别将背景和前景颜色重置为默认值 |
FS
读取
使用 ez_rust::fs
读取文件
use ez_rust::fs
fn main() {
let file: String = fs::read_file("path/to/file.txt");
}
写入
使用 ez_rust::fs
写入文件
use ez_rust::fs
fn main() {
let err: bool = fs::write_file("path/to/file.txt", "hello");
/* err is a boolean wich will be true if an error occcurd while writing to the file */
}
创建
使用 ez_rust::fs
创建文件
use ez_rust::fs
fn main() {
let err: bool = fs::create_file("path/to/file.txt", "hello");
/* err is a boolean wich will be true if an error occcurd while creating to the file */
}
创建和写入
使用 ez_rust::fs
创建并写入文件
use ez_rust::fs
fn main() {
let err: bool = fs::create_file_write("path/to/file.txt", "hello");
/* err is a boolean wich will be true if an error occcurd while creating or writing to the file */
}