Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
simsekgokhan committed Apr 23, 2024
1 parent 1827497 commit b60c85f
Show file tree
Hide file tree
Showing 16 changed files with 33 additions and 33 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ This repo is for my personal use with tips, tools, ready to use examples/explana
> . Use [unit_test](src/unit_tested_file.rs) (also use it in CI: [unit_tests.yml](.github/workflows/unit_tests.yml))
> . Use `sccache` for faster builds (see setup and how to use in section "docs" below)
> . Use [.cargo/config.toml](.cargo/config.toml) (see `faster_builds_with_linker_config` in section "docs" below)
> . Use debugger (see vscode debugger setup, examples in section "docs" below) or use `RUST_BACKTRACE=1 cargo run ...`
> . Use debugger (see vscode debugger setup, examples in section "docs" below) or use `RUST_BACKTRACE=1 cargo run . . .`
> . Use `cargo tree` - displays the dependency graph
#### [best-practice-tips/](best-practices)
Expand Down Expand Up @@ -90,4 +90,4 @@ This repo is for my personal use with tips, tools, ready to use examples/explana
- Debugging, `.vscode/launch.json` template
- `.cargo/config.toml` sample, including fastest linkers, very&more useful for big codebases
- Read from file, find lines that contains a string
- And more... see -> [src/*.rs](src/)
- And more. . . see -> [src/*.rs](src/)
4 changes: 2 additions & 2 deletions best-practices/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,13 @@ For this situation, an if let expression is one line shorter and, more important
return Err(format!("Failed to open password file: {:?}", e))
}
};
// ...
// . . .
}

pub fn find_user(username: &str) -> Result<UserId, String> {
let f = std::fs::File::open("/etc/passwd")
.map_err(|e| format!("Failed to open password file: {:?}", e))?;
// ...
// . . .
}
// Better still, even map_err may not be necessary – if the outer error type
// can be created from the inner error type via an implementation of the
Expand Down
2 changes: 1 addition & 1 deletion docs/how_to_debug_rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ E.g. two debug configs for `tower` package with and without using `cargo`:
```

#### Step-3
`File -> Preferences -> Settings` type `Allow setting breakpoints...`
`File -> Preferences -> Settings` type `Allow setting breakpoints. . .`

Tick this checkbox:
`<> Allow setting breakpoints in any file`
Expand Down
10 changes: 5 additions & 5 deletions src/async_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ async fn foo() -> u8 { 5 }


// 3. async await basic example
async fn learn_song() { for i in 1..=3 { println!("--- learning song... {}", i); } }
async fn learn_song() { for i in 1..=3 { println!("--- learning song. . . {}", i); } }

async fn sing() { for i in 1..=3 { println!("--- singing... {}", i); } }
async fn sing() { for i in 1..=3 { println!("--- singing. . . {}", i); } }

// 3.a. await - wait/block one future
async fn learn_and_sing() {
Expand All @@ -83,7 +83,7 @@ async fn learn_and_sing() {
}

async fn dance() {
for i in 1..=3 { println!("--- dancing... {}", i); }
for i in 1..=3 { println!("--- dancing. . . {}", i); }
}

// 3.b. join - wait/block multiple futures concurrently
Expand Down Expand Up @@ -112,8 +112,8 @@ async fn async_main() {
// 3.c. try_join - use it for futures which return Result
use futures::try_join;

async fn get_book() -> Result<i32, String> { /* ... */ Ok(42) }
async fn get_music() -> Result<i32, String> { /* ... */ Ok(43) }
async fn get_book() -> Result<i32, String> { /* . . . */ Ok(42) }
async fn get_music() -> Result<i32, String> { /* . . . */ Ok(43) }

async fn get_book_and_music() -> Result<(i32, i32), String> {
let book_fut = get_book();
Expand Down
2 changes: 1 addition & 1 deletion src/cacher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl<Function, Key, Val> Cacher<Function, Key, Val>
println!("Cacher: cashed result for {}: {}", arg, val);
val
} else {
println!("Cacher: calculating for {}...", arg);
println!("Cacher: calculating for {} . . .", arg);
let val = (self.function)(arg);
self.results.insert(arg, val);
val
Expand Down
2 changes: 1 addition & 1 deletion src/env.vars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Run time env. vars use
// .cargo/config.toml
// [env]
// ...
// . . .
// see main.rs for usage

// Todo
Expand Down
6 changes: 3 additions & 3 deletions src/env_logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ fn ex1() {
info!("this is info {}", "message");
debug!("this is a debug {}", "message");
}
// $ RUST_LOG=error cargo r ...
// $ RUST_LOG=error cargo r
// [2023-11-09T02:12:24Z ERROR main] this is printed by default

// $ RUST_LOG=info cargo r ...
// $ RUST_LOG=info cargo r
// [2023-11-09T02:12:24Z ERROR main] this is printed by default
// [2023-11-09T02:12:24Z INFO main] this is info

// $ RUST_LOG=debug cargo r ...
// $ RUST_LOG=debug cargo r
// [2023-11-09T02:12:24Z ERROR main] this is printed by default
// [2023-11-09T02:12:24Z INFO main] this is info
// [2023-11-09T02:12:24Z DEBUG main] this is a debug message
2 changes: 1 addition & 1 deletion src/error_handling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ fn ex_b_1() {
// panics with `Error xyz happened`: emergency failure`
}

// Using match - same as `expect("...")` in ex_1:
// Using match - same as `expect(". . .")` in ex_1:
#[test]
#[should_panic] // Comment to see the panic
fn ex_b_2() {
Expand Down
18 changes: 9 additions & 9 deletions src/int_overflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@
#[should_panic] // comment this line to see the panic
#[test] fn ex_1_panics_w_int_overflow() {
let mut i: u16 = 0;
print!("{}..", i);
print!("{}-", i);
loop {
i += 1000;
print!("{}..", i);
print!("{}-", i);
if i % 10000 == 0 {
print!{"\n"}
}
}
// info: let sixty_five_thousand_535: u16 = 0b1111_1111_1111_1111;
}
// cout:
// 0..1000..2000..3000..4000..5000..6000..7000..8000..9000..10000..
// 11000..12000..13000..14000..15000..16000..17000..18000..19000..20000..
// 21000..22000..23000..24000..25000..26000..27000..28000..29000..30000..
// 31000..32000..33000..34000..35000..36000..37000..38000..39000..40000..
// 41000..42000..43000..44000..45000..46000..47000..48000..49000..50000..
// 51000..52000..53000..54000..55000..56000..57000..58000..59000..60000..
// 61000..62000..63000..64000..65000..
// 0-1000-2000-3000-4000-5000-6000-7000-8000-9000-10000-
// 11000-12000-13000-14000-15000-16000-17000-18000-19000-20000-
// 21000-22000-23000-24000-25000-26000-27000-28000-29000-30000-
// 31000-32000-33000-34000-35000-36000-37000-38000-39000-40000-
// 41000-42000-43000-44000-45000-46000-47000-48000-49000-50000-
// 51000-52000-53000-54000-55000-56000-57000-58000-59000-60000-
// 61000-62000-63000-64000-65000-
// thread 'int_overflow::ex_1_panics_w_overflow' panicked at 'attempt to
// add with overflow', src/int_overflow.rs:6:9

Expand Down
2 changes: 1 addition & 1 deletion src/iterators_aka_algorithms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
pub trait Iterator {
type Item; // The type of the elements being iterated over aka type placeholder
fn next(&mut self) -> Option<Self::Item>;
// ...
// . . .
}

// =======
Expand Down
2 changes: 1 addition & 1 deletion src/let_else.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn process_str(s: &str) -> u64 {
}
let count = res.unwrap();

// ... do_something_with(count)
// . . . do_something_with(count)
count + 1
}

Expand Down
2 changes: 1 addition & 1 deletion src/match_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
}


/// 3. Matching Ranges of Values with the ... Syntax
/// 3. Matching Ranges of Values with the . . . Syntax
#[test] fn ex_3() {
let x = 5;
match x {
Expand Down
2 changes: 1 addition & 1 deletion src/string_concat.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

// 0. String from String and &strs
// Note:
// String = String + &str + &str etc..
// String = String + &str + &str etc.
// ^
// first arg must be String
#[test] fn ex_0_string_from_strings_and_strs() {
Expand Down
2 changes: 1 addition & 1 deletion src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl<T> Screen_Static_Dispatch<T> where T: Draw {
// -------------------------------------------------------------------


// 1.a. DYNAMIC dispatch ...continues...
// 1.a. DYNAMIC dispatch . . .continues. . .
pub struct Button {
pub width: u32,
pub height: u32,
Expand Down
4 changes: 2 additions & 2 deletions src/traits_associated_type_vs_generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub trait Iterator {
// concrete type

fn next(&mut self) -> Option<Self::Item>;
// ...
// . . .
}

// Creating Our Own Iterator
Expand All @@ -40,7 +40,7 @@ impl Iterator for Counter {
// // Creating Our Own Iterator - 2
// impl Iterator for Counter {
// type Item = String;
// // ...
// // . . .
// }

#[test] fn iter_our_iter_next() {
Expand Down
2 changes: 1 addition & 1 deletion src/type_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub trait Iterator {
type Item; // The type of the elements being iterated over

fn next(&mut self) -> Option<Self::Item>;
// ...
// . . .
}

// Simple usage of iterators
Expand Down

0 comments on commit b60c85f

Please sign in to comment.