first commit
This commit is contained in:
+54
@@ -0,0 +1,54 @@
|
|||||||
|
# Generated by Cargo
|
||||||
|
# will have compiled files in the `$OUT_DIR` folder
|
||||||
|
/target/
|
||||||
|
|
||||||
|
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
|
||||||
|
# Cargo.lock
|
||||||
|
|
||||||
|
# For IntelliJ
|
||||||
|
.idea/
|
||||||
|
|
||||||
|
# For Visual Studio Code
|
||||||
|
.vscode/
|
||||||
|
|
||||||
|
# For Vim
|
||||||
|
*.swp
|
||||||
|
*.swo
|
||||||
|
*~
|
||||||
|
|
||||||
|
# For Emacs
|
||||||
|
*~
|
||||||
|
\#*\#
|
||||||
|
/.emacs.desktop
|
||||||
|
/.emacs.desktop.lock
|
||||||
|
*.elc
|
||||||
|
auto-save-list
|
||||||
|
tramp
|
||||||
|
.\#*
|
||||||
|
|
||||||
|
# For Sublime Text
|
||||||
|
*.tmlanguage.cache
|
||||||
|
*.tmPreferences.cache
|
||||||
|
*.stTheme.cache
|
||||||
|
|
||||||
|
# For Kate
|
||||||
|
.session
|
||||||
|
.sessions
|
||||||
|
|
||||||
|
# For Firefox Developer Edition
|
||||||
|
devtools.chrome.extension.build/
|
||||||
|
|
||||||
|
# For Mac
|
||||||
|
.DS_Store
|
||||||
|
|
||||||
|
# For Linux
|
||||||
|
*~
|
||||||
|
|
||||||
|
# For Windows
|
||||||
|
Thumbs.db
|
||||||
|
ehthumbs.db
|
||||||
|
Icon?
|
||||||
|
desktop.ini
|
||||||
|
|
||||||
|
# For Cargo documentation
|
||||||
|
/doc/
|
||||||
Generated
+7
@@ -0,0 +1,7 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rust_project"
|
||||||
|
version = "0.1.0"
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "rust_project"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
-1
Submodule rust_project deleted from 4145a856dc
+45
@@ -0,0 +1,45 @@
|
|||||||
|
use std::io;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
println!("欢迎来到增强版 Rust 程序!");
|
||||||
|
|
||||||
|
// 演示变量声明和类型d
|
||||||
|
let name = "Rustacean"; // Rustacean 是 Rust 开发者的昵称
|
||||||
|
let age: u32 = 10;
|
||||||
|
|
||||||
|
println!("你好,{}!你使用 Rust 已经 {} 年了。", name, age);
|
||||||
|
|
||||||
|
// 演示数组和循环
|
||||||
|
let numbers = [1, 2, 3, 4, 5];
|
||||||
|
println!("\n数字列表:");
|
||||||
|
for (index, &value) in numbers.iter().enumerate() {
|
||||||
|
println!("索引 {}: 值 {}", index, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算数组元素总和
|
||||||
|
let sum: i32 = numbers.iter().sum();
|
||||||
|
println!("\n数组元素总和: {}", sum);
|
||||||
|
|
||||||
|
// 条件判断
|
||||||
|
if sum > 10 {
|
||||||
|
println!("总和大于 10");
|
||||||
|
} else {
|
||||||
|
println!("总和小于或等于 10");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 与用户交互
|
||||||
|
println!("\n请输入您的名字:");
|
||||||
|
let mut input = String::new();
|
||||||
|
|
||||||
|
match io::stdin().read_line(&mut input) {
|
||||||
|
Ok(_) => {
|
||||||
|
let input = input.trim(); // 移除换行符
|
||||||
|
if !input.is_empty() {
|
||||||
|
println!("很高兴认识您,{}!", input);
|
||||||
|
} else {
|
||||||
|
println!("您没有输入任何内容。");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(error) => println!("读取输入时发生错误: {}", error),
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user