rust 判断 windows linux 系统

rust 判断 windows linux 系统

use std::io::stdin;//1 use std::process::Command; fn main() { // cmd_str可以是从输入流读取或从文件里读取 let cmd_str: String; println!("linux{}", cfg!(target_os = "linux")); println!("windows{}", cfg!(target_os = "windows")); if cfg!(target_os = "windows") { ...

Rust 2023-03-11 PM 550℃ 0条
rust 命令行 清屏

rust 命令行 清屏

print!("\x1b[2J"); print!("\x1b[H");

Rust 2023-03-11 PM 541℃ 0条
rust-打开windows10电脑启动配置

rust-打开windows10电脑启动配置

rust-打开windows10电脑启动配置main.rs#![windows_subsystem = "windows"] use std::process::Command; use std::os::windows::process::CommandExt; fn main() { let output = if cfg!(target_os = "windows") { Command::new("cmd") .creation_flags(0x08000000...

Rust 2023-03-11 PM 515℃ 0条
rust-打开系统信息

rust-打开系统信息

rust-打开系统信息main.rs#![windows_subsystem = "windows"] use std::process::Command; use std::os::windows::process::CommandExt; fn main() { let output = if cfg!(target_os = "windows") { Command::new("cmd") .creation_flags(0x08000000) ...

Rust 2023-03-11 PM 525℃ 0条
rust计算程序运行时间

rust计算程序运行时间

rust计算程序运行时间main.rsuse std::thread::sleep; use std::time::{Duration,Instant}; fn main() { let now = Instant::now(); // 程序起始时间 println!("{:?}",now); let three_seconds = Duration::from_secs(3); sleep(three_seconds); // 延迟3秒 let end = now.elapsed().as_secs(); ...

Rust 2023-03-11 PM 506℃ 0条
rust-延迟5秒锁屏

rust-延迟5秒锁屏

实例-rust-延迟5秒锁屏main.rs#![windows_subsystem = "windows"] use std::process::Command; use std::os::windows::process::CommandExt; use std::thread::sleep; use std::time::Duration; fn main() { let time_seconds = Duration::from_secs(5); sleep(time_seconds); // 延迟5秒执行以下程序 let outp...

Rust 2023-03-11 PM 603℃ 0条
rust执行cmd命令隐藏dos窗口-打开环境变量

rust执行cmd命令隐藏dos窗口-打开环境变量

https://blog.csdn.net/weixin_35894173/article/details/112282032https://rustcc.cn/article?id=f1630b61-4637-4e80-8414-8a921af50d68主要原理是,通过函数creation_flags设置CreateProcess函数的creation flags,设置为 隐藏窗口即可。关键命令:![windows_subsystem = "windows"]use std::os::windows::process::CommandExt;.creation_flags(0x0800...

Rust 2023-03-11 PM 511℃ 0条
rust 实现摄氏温度与华氏温度相互转换

rust 实现摄氏温度与华氏温度相互转换

use std::io; // 实现摄氏温度与华氏温度相互转换 // 华式度 = 32 + 摄氏度 x 1.8; 摄氏度 = (华式度 - 32) / 1.8。(华式单位: °F, 摄氏单位: °C) fn main() { loop { println!("请输入要转换的温度类型:摄氏温度【1】,华氏温度【2】"); let mut input = String::new(); io::stdin().read_line(&mut input).expect("读取异常"); ...

Rust 2023-03-11 AM 517℃ 0条
rust 打开浏览器

rust 打开浏览器

use webbrowser; fn main() { if webbrowser::open("http://www.180it.com/").is_ok() { println!("Open!"); } }

Rust 2023-03-11 AM 423℃ 0条
rust 遍历迭代器

rust 遍历迭代器

fn main() { let v1 = vec![1, 2, 3]; // 迭代器是惰性的,创建迭代器后,除非主动调用,否则不会产生任何实际效果 // 创建迭代器 let v1_iter = v1.iter(); // 使用 for 进行遍历 for val in v1_iter { println!("Got: {}", val); } }

Rust 2023-03-11 AM 351℃ 0条
rust 线程演示

rust 线程演示

use std::thread; use std::time::Duration; fn main() { let handle = thread::spawn(|| { for i in 1..10 { println!("hi number {} from the spawned thread!", i); thread::sleep(Duration::from_millis(1)); } }); // 如果放置在这里,由于主线程会等待新线程执行完毕后才开始...

Rust 2023-03-11 AM 416℃ 0条