first: commit
This commit is contained in:
commit
ec76bc9dbd
|
|
@ -0,0 +1 @@
|
||||||
|
/target
|
||||||
|
|
@ -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"
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
[package]
|
||||||
|
name = "rust-one"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
|
@ -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()
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue