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

6
slices/Cargo.toml Normal file
View file

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

27
slices/src/main.rs Normal file
View file

@ -0,0 +1,27 @@
fn main() {
//slices are a way to reference a contigous sequence of elements in a collection, without
//owning the data. they let you work with parts of arryas, vectors or strings
//- slices are view into collection
//-they don't own the data, just borrow it
//- &[T] for a slice of elements of type T
let arr = [1,2,3,4,5,50];
let slice = &arr[1..4];
println!("{:?}", slice);
//slice of vector
let vec = vec![2,3,4,5];
let slicer = &vec[2..];
println!("{:?}", slicer);
//string slice
let str = String::from("safal lama");
let slc = &str[0..];
println!("{:?}", slc);
//Slices allow safe, efficient access to parts of collections without copying data.
}