rust 随机数字

rust 随机数字

use rand::prelude::*; fn main() { let secret = rand::thread_rng().gen_range(0..101); println!("神秘数字是:{}", secret); }

Rust 2023-03-11 AM 475次 0条
rust 命令行接收输入并输出

rust 命令行接收输入并输出

use std::cmp::Ordering;use std::io; fn main() { println!("请输入路径:"); let mut guess = String::new(); io::stdin().read_line(&mut guess).expect("读取异常");...

Rust 2023-03-11 AM 625次 0条
rust 创建多层文件夹

rust 创建多层文件夹

use std::fs; fn main() -> std::io::Result<()> { // 创建文件夹 fs::create_dir("setting")?; // 一次创建多级文件夹 fs::create_dir_all("setting/myapp/networksettings")?...

Rust 2023-03-11 AM 748次 0条
rust 操作文本 写入 读取 追加

rust 操作文本 写入 读取 追加

use std::fs; use std::io::{self, Write}; //文件创建/导入 // 写入 fn open() -> std::io::Result<()> { let mut file = fs::File::create("textfile.txt")?; file.write_all(b"New ...

Rust 2023-03-11 AM 705次 0条
rust UdpSocket 通信

rust UdpSocket 通信

use std::net::UdpSocket; use std::str; fn main() -> std::io::Result<()> { let remote_addr = "localhost:8888"; let socket = UdpSocket::bind("localhost:0")?; ...

Rust 2023-03-11 AM 497次 0条
rust 复制文本文件

rust 复制文本文件

use std::env; use std::fs::File; use std::io; fn main() -> io::Result<()> { let args: Vec<_> = env::args().collect(); let src = &args[1]; let dest = &args[2]; ...

Rust 2023-03-10 PM 915次 0条
rust 创建zip压缩包并写入文本

rust 创建zip压缩包并写入文本

use std::fs::File; use std::io; use std::io::Write; fn main() -> io::Result<()> { let file = File::create("file.zip")?; let mut zip = zip::ZipWriter::new(file); zip...

Rust 2023-03-10 PM 608次 0条
rust写个简单爬虫

rust写个简单爬虫

Cargo.toml 配置[dependencies] scraper = "0.12.0" reqwest = { version = "0.11.10", features = ["blocking", "json"] } surf = "2.3.2" tokio = { version ...

Rust 2023-03-10 AM 551次 0条
rust 逐行读取文本

rust 逐行读取文本

use std::io::prelude::*; use std::fs::File; use std::io::BufWriter; use std::io::BufReader; fn main() { let file = File::open("./ico.txt").unwrap(); let mut fin = BufReader::new(...

Rust 2023-03-10 AM 527次 0条
Rust Cargo 指定国内镜像

Rust Cargo 指定国内镜像

参考https://huangjj27.gitlab.io/posts/rust-mirrorhttps://doc.rust-lang.org/cargo/reference/source-replacement.htmlhttps://lug.ustc.edu.cn/wiki/mirrors/help/rust-crateshttps://github.com/rustcc/lernae...

Rust 2023-03-08 PM 726次 0条
Rust 文件批量添加换行符

Rust 文件批量添加换行符

本文代码 https://github.com/tothis/rust-record/tree/main/cli/file-append-newlineCargo.toml[package] name = "file-append-newline" version = "0.1.0" authors = ["Li Lei <this.l...

Rust 2023-03-08 PM 692次 0条