Implementing common concepts
This commit is contained in:
parent
fbc67ccaec
commit
d0a0d267da
23
.gitignore
vendored
Normal file
23
.gitignore
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
# Generated by Cargo
|
||||
# will have compiled files and executables
|
||||
debug/
|
||||
target/
|
||||
|
||||
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
|
||||
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
|
||||
Cargo.lock
|
||||
|
||||
# These are backup files generated by rustfmt
|
||||
**/*.rs.bk
|
||||
|
||||
# MSVC Windows builds of rustc generate these, which store debugging information
|
||||
*.pdb
|
||||
|
||||
# RustRover
|
||||
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
||||
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||
#.idea/
|
||||
**/target
|
||||
**/debug
|
7
common_concepts/Cargo.lock
generated
Normal file
7
common_concepts/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 = "common_concepts"
|
||||
version = "0.1.0"
|
6
common_concepts/Cargo.toml
Normal file
6
common_concepts/Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "common_concepts"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
BIN
common_concepts/main
Executable file
BIN
common_concepts/main
Executable file
Binary file not shown.
41
common_concepts/src/main.rs
Normal file
41
common_concepts/src/main.rs
Normal file
@ -0,0 +1,41 @@
|
||||
fn add(a:i32,b:i32) -> i32{
|
||||
return a + b;
|
||||
}
|
||||
fn addOne(a:i32) -> i32 {
|
||||
return a + 1;
|
||||
}
|
||||
fn generate(limit:i32) -> Vec<i32>{
|
||||
let mut arr:Vec<i32> = Vec::new();
|
||||
for x in 1..limit {
|
||||
arr.push(x);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
fn generate_with(limit:i32,generator_func:fn(i32) -> i32) -> Vec<i32> {
|
||||
let mut arr:Vec<i32> = Vec::new();
|
||||
for x in generate(limit) {
|
||||
arr.push(generator_func(x));
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
fn main() {
|
||||
let mut count = 0;
|
||||
let mut i = 0;
|
||||
while i < 100 {
|
||||
|
||||
count = count + i;
|
||||
i = i + 1;
|
||||
}
|
||||
println!("Count with while loop:{}",count);
|
||||
count = 0;
|
||||
for x in generate(100) {
|
||||
count = count + x;
|
||||
}
|
||||
println!("Count with array generation:{}",count);
|
||||
count = generate(100).iter().sum();
|
||||
println!("Count with generation:{}",count);
|
||||
count = generate_with(100,|x| x + 1).into_iter().sum();
|
||||
println!("Count with generation_with:{}",count);
|
||||
count = generate_with(100,addOne).into_iter().sum();
|
||||
println!("Count with generation_with and function as parameter:{}",count);
|
||||
}
|
1
common_concepts/target/.rustc_info.json
Normal file
1
common_concepts/target/.rustc_info.json
Normal file
@ -0,0 +1 @@
|
||||
{"rustc_fingerprint":12748942277069595422,"outputs":{"4614504638168534921":{"success":true,"status":"","code":0,"stdout":"rustc 1.83.0 (90b35a623 2024-11-26)\nbinary: rustc\ncommit-hash: 90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\ncommit-date: 2024-11-26\nhost: x86_64-unknown-linux-gnu\nrelease: 1.83.0\nLLVM version: 19.1.1\n","stderr":""},"15729799797837862367":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n/home/adnanwork/.rustup/toolchains/stable-x86_64-unknown-linux-gnu\noff\npacked\nunpacked\n___\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_abi=\"\"\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"gnu\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"linux\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"unknown\"\nunix\n","stderr":""}},"successes":{}}
|
3
common_concepts/target/CACHEDIR.TAG
Normal file
3
common_concepts/target/CACHEDIR.TAG
Normal file
@ -0,0 +1,3 @@
|
||||
Signature: 8a477f597d28d172789f06886806bc55
|
||||
# This file is a cache directory tag created by cargo.
|
||||
# For information about cache directory tags see https://bford.info/cachedir/
|
0
common_concepts/target/debug/.cargo-lock
Normal file
0
common_concepts/target/debug/.cargo-lock
Normal file
1
common_concepts/target/debug/.fingerprint/common_concepts-c8c763753bc2e524/bin-common_concepts
Normal file
1
common_concepts/target/debug/.fingerprint/common_concepts-c8c763753bc2e524/bin-common_concepts
Normal file
@ -0,0 +1 @@
|
||||
9b1c6090b16909a0
|
1
common_concepts/target/debug/.fingerprint/common_concepts-c8c763753bc2e524/bin-common_concepts.json
Normal file
1
common_concepts/target/debug/.fingerprint/common_concepts-c8c763753bc2e524/bin-common_concepts.json
Normal file
@ -0,0 +1 @@
|
||||
{"rustc":11594289678289209806,"features":"[]","declared_features":"[]","target":9469802781527107148,"profile":11597332650809196192,"path":10602529704205407992,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/common_concepts-c8c763753bc2e524/dep-bin-common_concepts","checksum":false}}],"rustflags":[],"metadata":7797948686568424061,"config":2202906307356721367,"compile_kind":0}
|
BIN
common_concepts/target/debug/.fingerprint/common_concepts-c8c763753bc2e524/dep-bin-common_concepts
Normal file
BIN
common_concepts/target/debug/.fingerprint/common_concepts-c8c763753bc2e524/dep-bin-common_concepts
Normal file
Binary file not shown.
1
common_concepts/target/debug/.fingerprint/common_concepts-c8c763753bc2e524/invoked.timestamp
Normal file
1
common_concepts/target/debug/.fingerprint/common_concepts-c8c763753bc2e524/invoked.timestamp
Normal file
@ -0,0 +1 @@
|
||||
This file has an mtime of when this was started.
|
3
common_concepts/target/debug/.fingerprint/common_concepts-c8c763753bc2e524/output-bin-common_concepts
Normal file
3
common_concepts/target/debug/.fingerprint/common_concepts-c8c763753bc2e524/output-bin-common_concepts
Normal file
@ -0,0 +1,3 @@
|
||||
{"$message_type":"diagnostic","message":"function `add` is never used","code":{"code":"dead_code","explanation":null},"level":"warning","spans":[{"file_name":"src/main.rs","byte_start":3,"byte_end":6,"line_start":1,"line_end":1,"column_start":4,"column_end":7,"is_primary":true,"text":[{"text":"fn add(a:i32,b:i32) -> i32{","highlight_start":4,"highlight_end":7}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"`#[warn(dead_code)]` on by default","code":null,"level":"note","spans":[],"children":[],"rendered":null}],"rendered":"\u001b[0m\u001b[1m\u001b[33mwarning\u001b[0m\u001b[0m\u001b[1m: function `add` is never used\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m--> \u001b[0m\u001b[0msrc/main.rs:1:4\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\n\u001b[0m\u001b[1m\u001b[38;5;12m1\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\u001b[0m \u001b[0m\u001b[0mfn add(a:i32,b:i32) -> i32{\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[33m^^^\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m= \u001b[0m\u001b[0m\u001b[1mnote\u001b[0m\u001b[0m: `#[warn(dead_code)]` on by default\u001b[0m\n\n"}
|
||||
{"$message_type":"diagnostic","message":"function `addOne` should have a snake case name","code":{"code":"non_snake_case","explanation":null},"level":"warning","spans":[{"file_name":"src/main.rs","byte_start":51,"byte_end":57,"line_start":4,"line_end":4,"column_start":4,"column_end":10,"is_primary":true,"text":[{"text":"fn addOne(a:i32) -> i32 {","highlight_start":4,"highlight_end":10}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"`#[warn(non_snake_case)]` on by default","code":null,"level":"note","spans":[],"children":[],"rendered":null},{"message":"convert the identifier to snake case","code":null,"level":"help","spans":[{"file_name":"src/main.rs","byte_start":51,"byte_end":57,"line_start":4,"line_end":4,"column_start":4,"column_end":10,"is_primary":true,"text":[{"text":"fn addOne(a:i32) -> i32 {","highlight_start":4,"highlight_end":10}],"label":null,"suggested_replacement":"add_one","suggestion_applicability":"MaybeIncorrect","expansion":null}],"children":[],"rendered":null}],"rendered":"\u001b[0m\u001b[1m\u001b[33mwarning\u001b[0m\u001b[0m\u001b[1m: function `addOne` should have a snake case name\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m--> \u001b[0m\u001b[0msrc/main.rs:4:4\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\n\u001b[0m\u001b[1m\u001b[38;5;12m4\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\u001b[0m \u001b[0m\u001b[0mfn addOne(a:i32) -> i32 {\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[33m^^^^^^\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[33mhelp: convert the identifier to snake case: `add_one`\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m= \u001b[0m\u001b[0m\u001b[1mnote\u001b[0m\u001b[0m: `#[warn(non_snake_case)]` on by default\u001b[0m\n\n"}
|
||||
{"$message_type":"diagnostic","message":"2 warnings emitted","code":null,"level":"warning","spans":[],"children":[],"rendered":"\u001b[0m\u001b[1m\u001b[33mwarning\u001b[0m\u001b[0m\u001b[1m: 2 warnings emitted\u001b[0m\n\n"}
|
BIN
common_concepts/target/debug/common_concepts
Executable file
BIN
common_concepts/target/debug/common_concepts
Executable file
Binary file not shown.
1
common_concepts/target/debug/common_concepts.d
Normal file
1
common_concepts/target/debug/common_concepts.d
Normal file
@ -0,0 +1 @@
|
||||
/home/adnanwork/repos/learn-rust/common_concepts/target/debug/common_concepts: /home/adnanwork/repos/learn-rust/common_concepts/src/main.rs
|
BIN
common_concepts/target/debug/deps/common_concepts-c8c763753bc2e524
Executable file
BIN
common_concepts/target/debug/deps/common_concepts-c8c763753bc2e524
Executable file
Binary file not shown.
@ -0,0 +1,5 @@
|
||||
/home/adnanwork/repos/learn-rust/common_concepts/target/debug/deps/common_concepts-c8c763753bc2e524: src/main.rs
|
||||
|
||||
/home/adnanwork/repos/learn-rust/common_concepts/target/debug/deps/common_concepts-c8c763753bc2e524.d: src/main.rs
|
||||
|
||||
src/main.rs:
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
common_concepts/target/debug/incremental/common_concepts-2874p2rsapvup/s-h2t8bdtb26-1nwbmpp-0wrzhk1m7unovcxume5brau6i/dep-graph.bin
Normal file
BIN
common_concepts/target/debug/incremental/common_concepts-2874p2rsapvup/s-h2t8bdtb26-1nwbmpp-0wrzhk1m7unovcxume5brau6i/dep-graph.bin
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
common_concepts/target/debug/incremental/common_concepts-2874p2rsapvup/s-h2t8bdtb26-1nwbmpp-0wrzhk1m7unovcxume5brau6i/query-cache.bin
Normal file
BIN
common_concepts/target/debug/incremental/common_concepts-2874p2rsapvup/s-h2t8bdtb26-1nwbmpp-0wrzhk1m7unovcxume5brau6i/query-cache.bin
Normal file
Binary file not shown.
BIN
common_concepts/target/debug/incremental/common_concepts-2874p2rsapvup/s-h2t8bdtb26-1nwbmpp-0wrzhk1m7unovcxume5brau6i/work-products.bin
Normal file
BIN
common_concepts/target/debug/incremental/common_concepts-2874p2rsapvup/s-h2t8bdtb26-1nwbmpp-0wrzhk1m7unovcxume5brau6i/work-products.bin
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user