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
ownership/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 = "ownership"
version = "0.1.0"

6
ownership/Cargo.toml Normal file
View file

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

51
ownership/src/main.rs Normal file
View file

@ -0,0 +1,51 @@
fn main() {
//ownership in rust is a centrla concept that governs how memory is managed. It ensures memory
//safety without neding a garbage collector.
//- each value in rust has owner
//- when the owner goes out of scope, the value is dropped
//- values can be moved or borrowed, but not both at the same time
let s1= String::from("safal");
let s2 = s1; //ownership moves to s2 from s1
println!("{}", s2);
//now instead of moving, lets borrow
let a1 = String::from("safallama");
safal(&a1);
println!("{}", a1);
let maxxa = String::from("pantimos");
takeownership(maxxa); //after this pulls up, the maxxa is dropped immediatedly
//
//
let maxxa = giveowenrship();
println!("{}", maxxa);
}
fn safal(s: &String){
println!("{}", s);
}
fn takeownership(s:String){
println!("got string{}",s);
}
fn giveowenrship()->String{
return String::from("ifrate");
}