تمرين إعادة البناء
Hello World Variations
أعد كتابة برنامج Rust يطبع تحيات ومعلومات بسيطة عن البيئة.
rust
~8 دقيقة
مبتدئ
أعد بناء الكود
Rebuild
هذا هو الكود. اكتبه بنفسك.
الكود المرجعي
use std::env;
use std::time::{SystemTime, UNIX_EPOCH};
fn main() {
// اطبع تحية — Print a greeting
println!("Hello from Rust rebuild practice!");
// اعرض النظام والمعمارية — Show OS and architecture
println!("OS: {}", env::consts::OS);
println!("Architecture: {}", env::consts::ARCH);
// اعرض مجلد التشغيل — Show the current working directory
match env::current_dir() {
Ok(path) => println!("Current directory: {}", path.display()),
Err(error) => println!("Could not read current directory: {error}"),
}
// اطبع الوقت كعدد ثوانٍ — Print time as Unix seconds
let now = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap_or_default()
.as_secs();
println!("Unix time: {now}");
}اكتب هنا