first commit

This commit is contained in:
Ashborn 2025-12-16 22:10:06 +05:45
commit a66604eb6c
52 changed files with 790 additions and 0 deletions

7
Structs/Cargo.lock generated Normal file
View file

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "Structs"
version = "0.1.0"

6
Structs/Cargo.toml Normal file
View file

@ -0,0 +1,6 @@
[package]
name = "Structs"
version = "0.1.0"
edition = "2024"
[dependencies]

50
Structs/src/main.rs Normal file
View file

@ -0,0 +1,50 @@
//Struct [Structure] is a custom data type that lets you group related values of different types
//under one name.
struct Person{
name: String,
age: i32
}
//structs with no fiels = unit like Structs
// struct Anime;
impl Person {
fn greet(&self){
println!("Hello, {}!", self.name);
}
fn new(name: &str)->Person{
Person { name: String::from(name),
age: 0
}
}
}
fn main() {
let mut person = Person{
name: String::from("safal lama"),
age: 21
};
person.age+=1;
let fav = Person {
name: String::from("aur"),
..person
};
println!("{}, {}", fav.name, fav.age);
// let m = Anime;
println!("{} is {} yrs old", person.name, person.age);
let a = Person::new("Safal");
a.greet();
}