first commit
This commit is contained in:
commit
a66604eb6c
52 changed files with 790 additions and 0 deletions
7
r_B/Cargo.lock
generated
Normal file
7
r_B/Cargo.lock
generated
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "r_B"
|
||||
version = "0.1.0"
|
||||
6
r_B/Cargo.toml
Normal file
6
r_B/Cargo.toml
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
[package]
|
||||
name = "r_B"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
29
r_B/src/main.rs
Normal file
29
r_B/src/main.rs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
fn main() {
|
||||
//borrowing => It means to allowing a function or variabe to use a value without taking
|
||||
//ownership : type:
|
||||
//- immutable borrowing [read only access]
|
||||
//- mutable borrowing [read write access]
|
||||
let s = String::from("hello world");
|
||||
print_strirng(&s);
|
||||
|
||||
let mut s1 = String::from("safal, hi");
|
||||
change_string(&mut s1);
|
||||
println!("{}", s1);
|
||||
|
||||
//ownership => It means every value in Rust has single owner, the variable responsible for it,
|
||||
//When ownership changes, the previous owner can no longer use the value
|
||||
|
||||
let owner = String::from("pantsu");
|
||||
let owner1 = owner;
|
||||
println!("{}", owner1);
|
||||
}
|
||||
|
||||
//borrowing but read only
|
||||
fn print_strirng(s: &String){
|
||||
println!("{} borrowed", s);
|
||||
}
|
||||
|
||||
fn change_string(s: &mut String){
|
||||
s.push_str("!!");
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue