commit ec76bc9dbd30a3bc1e052e2fcd683d47a1a2dedc Author: rizzOn Date: Mon Mar 9 01:12:56 2026 +0530 first: commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..d37db5b --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "rust-one" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..75bdcdb --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "rust-one" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..a787175 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,54 @@ +fn main() { + + // This is an example of variable shadowing + let _variable_one = "new string"; + let _variable_one = _variable_one.to_owned() + "second string"; + println!("Hello, world!"); + + let _array_one: [i32; 4] = [1,3,4,5]; + let _arrays = [4,5,45,5,5,5]; + let _tuple_one = (3,5,5,"fdsfd"); + + let _array_pointer: &[i32] = &[1,3,4,5,6,6]; + + let string_slice : &[String] = &["test string one ".to_string(), "this is the second string".to_string()]; + println!("this is a reference to a string array {:?}", string_slice); + + let mut string_owned :String = String::from("hello rust"); + let string_borrowed: &str = &string_owned; + println!("this is the borrowed string {}", string_borrowed); + string_owned.push_str("string"); + println!("this is the borrowed string value now {}", string_owned); + + + + let x = { + let first: i32 = 67; + let second = 54; + first * second + }; + let y = 56; + + println!("the is the value of the expression evaluated: {:?}", x); + + + println!("this is the value of a function expression evaluating to {:?}", add(x, y)); + + + let string_one_owner : String = String::from("im the ownee"); + println!("The size of string {} is {}.", string_one_owner, get_string_len(&string_one_owner)); + let _string_two_one_owner = string_one_owner; + println!("this is the original owner : {}", string_one_owner); + println!("this is the new owner : {}", _string_two_one_owner); + + +} + + +fn add (first :i32, second: i32) -> i32 { + first * second +} + +fn get_string_len(str :&String) -> usize { + str.len() +} \ No newline at end of file