🎉 initial commit

This commit is contained in:
2025-09-20 20:44:24 +08:00
commit 82538addcc
19 changed files with 483 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
use std::collections::HashMap;
fn process_data(data:Vec<i32>)->HashMap<i32,i32>{
let mut result=HashMap::new();
for(index,value)in data.iter().enumerate(){
result.insert(index as i32,*value*2);
}
result
}
#[cfg(test)]
mod tests{
use super::*;
#[test]
fn test_process_data(){
let input=vec![1,2,3,4,5];
let result=process_data(input);
assert_eq!(result.get(&0),Some(&2));
assert_eq!(result.get(&1),Some(&4));
}
}

View File

@@ -0,0 +1,19 @@
use std::collections::HashMap;
fn process_data(data: Vec<i32>) -> HashMap<i32, i32> {
let mut result = HashMap::new();
for (index, value) in data.iter().enumerate() {
result.insert(index as i32, *value * 2);
}
result
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_process_data() {
let input = vec![1, 2, 3, 4, 5];
let result = process_data(input);
assert_eq!(result.get(& 0), Some(& 2));
assert_eq!(result.get(& 1), Some(& 4));
}
}

View File

@@ -0,0 +1,5 @@
fn main(){println!("Hello, world!");}
fn add(a:i32,b:i32)->i32{
a+b
}

View File

@@ -0,0 +1,6 @@
fn main() {
println!("Hello, world!");
}
fn add(a: i32, b: i32) -> i32 {
a + b
}

View File

@@ -0,0 +1,11 @@
struct Person{name:String,age:u32}
impl Person{
fn new(name:String,age:u32)->Self{
Self{name,age}
}
fn greet(&self){
println!("Hello, my name is {} and I'm {} years old.",self.name,self.age);
}
}

View File

@@ -0,0 +1,12 @@
struct Person {
name: String,
age: u32,
}
impl Person {
fn new(name: String, age: u32) -> Self {
Self { name, age }
}
fn greet(&self) {
println!("Hello, my name is {} and I'm {} years old.", self.name, self.age);
}
}