Skip to content

New tutorials #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 77 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
66acba9
Initial addition for example with Smart pointers
bsodmike Apr 11, 2022
3b3a141
Add example to convert String to Vec<u8> and back
bsodmike Apr 11, 2022
464d368
Add example with UnsafeCell
bsodmike Apr 11, 2022
070d7c6
Add comments
bsodmike Apr 11, 2022
70f36bd
Add note
bsodmike Apr 11, 2022
a769b9a
Add notes
bsodmike Apr 12, 2022
1c65578
WIP start on Traits
bsodmike Nov 14, 2022
6538841
Add notes on use of `impl Trait` on a fn parameter
bsodmike Nov 14, 2022
193c439
FIX organisations of modules
bsodmike Nov 16, 2022
1e1b354
WIP initial approach
bsodmike Nov 16, 2022
bb093b4
Add method to provide short version of the weekday
bsodmike Nov 16, 2022
753b736
FIX: Make sure lib.rs is implemented correctly
bsodmike Nov 17, 2022
335b359
Example for use of traits and trait objects from `esp_idf_hal`
bsodmike Nov 21, 2022
22cc4f3
Update example for using PeripheralRef
bsodmike Nov 21, 2022
c6ccbd4
Cleanup
bsodmike Dec 8, 2022
9bb2638
Add example of using closure to spawn parallel tasks with Tokio
bsodmike Apr 22, 2023
3f4f00a
Add examples on using static/dynamic despatch with closures
bsodmike May 16, 2023
d94e1ad
Add lesson 4
bsodmike May 23, 2023
4f23d2a
Add example for object-safe approach to calling generic method on tra…
bsodmike Jul 15, 2023
353781a
Cleanup
bsodmike Jul 15, 2023
87cf99b
Add example with downcasting trait objects using dyn Any
bsodmike Jul 16, 2023
79eda38
Add lesson 6 - digging into Axum
bsodmike Aug 10, 2023
c4f4837
Update Traits lesson 7
bsodmike Sep 2, 2023
1461729
Add example based on IMAP crate
bsodmike Sep 14, 2023
5157035
Add example for pbkdf AES enc (still in progress, may have mistakes)
bsodmike Mar 19, 2024
480c439
Initial addition for PartialEq
bsodmike Mar 23, 2024
065b0d9
FIX tests
bsodmike Mar 23, 2024
861ad33
Add example for correctly handling panics with Tokio threads
Aug 21, 2024
16340c3
Add example demonstrating in memory searching of Strings and data
Aug 22, 2024
7c01289
WIP: Add benchmarking option for flamegraphing
Aug 23, 2024
d6ad6bb
Remove comment in main
Aug 23, 2024
44d082d
FIXME: testing in release mode causes ICE
Aug 23, 2024
a8bb3d1
FIXME: use `black_box` correctly
Aug 23, 2024
2624695
WIP initial profiling with flamegraph
Aug 23, 2024
ad249ba
WIP setup core and another bin to assist with heaptrack memory profiling
Aug 23, 2024
f5b5625
FIX: Strip out need for async, KISS...!
Aug 23, 2024
461b20b
FIX: Remove unused argument
Aug 23, 2024
c0f57cf
Remove use of LazyLock and switch to `&mut self` to avoid extra cloni…
Aug 24, 2024
64a7b11
FIX: remove unnecessary cloning of HashMap
Aug 24, 2024
525f8cd
FIX: remove stupid approach at creating a f64 range
Aug 25, 2024
3b7b6e2
FIX: use rand to generate a random max word length
Aug 25, 2024
2250f26
Add script to run heaptrack
Aug 25, 2024
7f73e6e
FIX: Rewrite phrase generation logic with note only optionally failin…
Aug 25, 2024
227a816
FIX: further cleanup for previous change
Aug 25, 2024
1f55a4c
FIX: further cleanup for previous change (again)
Aug 25, 2024
04b44e7
FIX: Make sure `Entries::search()` is exercised
Aug 25, 2024
79a9a2a
FIX: Remove remnant map() that has no effect, and unnecessary now
Aug 25, 2024
c0c32b9
Further cleanup, move tests into lib
Aug 26, 2024
cba4920
WIP tweak invocation count for flamegraph
Aug 26, 2024
9056922
FIX: Do not alloc unnecessary Vec when searching HashMap
Aug 27, 2024
8af5357
Add flamegraph
Aug 27, 2024
8476c2a
FIX: Clean up string_search/core
Aug 27, 2024
70f7eb6
FIX: use relative path for running heaptrack
Aug 27, 2024
6f49360
Readability clean up
Aug 27, 2024
df0702c
FIX: Entries::search() returns cost of found needle only
Aug 27, 2024
9a5a14f
Add `phrases_randomized`
Aug 27, 2024
0b5a059
Add example on a swappable storage backend
Sep 4, 2024
f9f7e54
Remove unused imports
Sep 4, 2024
51c8077
FIXME: LimitReader expects only the type that it contains, it can't s…
Sep 4, 2024
5e8271c
Apply crude fix by removing `R` type dependency on Object; needs clea…
Sep 4, 2024
bd28131
Finish writing basic tests; Object needs a better name
Sep 5, 2024
4115245
Cleanup and rename Object to LimitReader
Sep 5, 2024
a1567b2
Add example on trait objects and `Sized`
Oct 25, 2024
cd4c456
Add example to demonstrate need for use of `?Sized` bound
Oct 25, 2024
5425af9
Add example for dereferencing a ptr using unsafe
Oct 25, 2024
63105c8
Add example using pinning
Nov 21, 2024
5f800ce
Add previous example on using Box<str>
Nov 21, 2024
db62a9b
Add more examples on pinning
Nov 22, 2024
12b0785
Add example on using `pin_project`
Nov 22, 2024
9aac87f
Formatting
Dec 1, 2024
61e32d3
Add example on using Newtype to adapt to trait bounds on generics
Dec 2, 2024
fd2d4e3
Add unfinished examples
Dec 15, 2024
8184f83
Add example on parsing with nom
Dec 22, 2024
1fcb8ea
Add super simple example on type-erasure of a writable backend
Dec 22, 2024
be96392
chore: add example with retry strategy using backon
bsodmike Mar 19, 2025
6f992d2
fix: typo
bsodmike Mar 19, 2025
a498f19
chore: Postgres multi-repository pattern with traits
bsodmike Mar 23, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/target
/examples/**/target/*
/.vscode
Cargo.lock

/flamegraph.svg
62 changes: 62 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,73 @@ version = "0.1.0"
edition = "2021"
publish = false

[[bin]]
name = "tokio-panic-handling"
path = "src/bin/tokio-panic-handling.rs"

[[bin]]
name = "string-search-heaptrack"
path = "src/bin/string-search-heaptrack.rs"

[[bin]]
name = "phrases-randomized"
path = "src/bin/phrases-randomized.rs"

[dependencies]
anyhow = "1.0.66"
futures = "0.3.19"
hyper = { version = "0.14.16", features = ["full"] }
hyper-rustls = { version = "0.23.0", features = ["http1", "http2"] }
tokio = { version = "1.17.0", features = ["full"] }
tokio-util = "0.7.7"
rustls = "0.21.0"
clap = { version = "3", features = ["derive"] }
dotenv = "0.15.0"
env_logger = "0.9.0"
log = "0.4.16"
http-body = "0.4.5"
bufstream = "0.1.3"
base64 = "0.21"
imap-proto = "0.16.1"
rustls-connector = { version = "0.18.0", features = ["dangerous-configuration"] }
hmac = { version = "0.13.0-pre.3" }
pbkdf2 = { version = "0.13.0-pre.0" }
sha2 = { version = "0.11.0-pre.3" }
hex-literal = "^0.4"
hex = "^0.4"
aes-gcm-siv = "^0.11"
aes = "^0.8"
heapless = "^0.8"
rand = "0.8.5"
pin-project = "1.1.7"
nalgebra = "0.33.2"
nom = "7.1.3"
async-trait = "0.1.83"
reqwest = "0.12.15"

# Misc
crossbeam = { version = "0.8.4", features = ["crossbeam-channel"] }
kanal = "0.1.0-pre8"

axum = { version = "0.6.18", features = ["headers", "tower-log"] }
axum-extra = "0.1.2"

# Axum builds on the types in Tower
tower = { version = "0.4.13", features = ["limit", "load-shed", "filter", "util"] }
tower-http = { version = "0.4.0", features = ["trace", "cors", "catch-panic"] }
tower-layer = "0.3.1"
tower-service = "0.3.1"
tower-http_0_2_4 = { package = "tower-http", version = "0.2.4" , features = ["cors"] }

# Logging support
tracing = "0.1.30"
tracing-subscriber = { version = "0.3.8", features = ["env-filter"] }
backon = "1.4.0"
bytes = "1.10.1"
thiserror = "2.0.12"

[dev-dependencies]
test-log = "0.2.10"

[profile.release]
debug = true
3 changes: 2 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
The MIT License (MIT)

Copyright (c) 2021 Michael de Silva (https://desilva.io/about)
Copyright (c) Michael de Silva (https://desilva.io/about)
Email: [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

This repo means to serve as a playground for expressing concepts quickly, in a "Rust by Example" format.

## Examples

Run the following with `cargo r --bin <PACKAGE_NAME>`

1. `tokio-panic-handling`



## License Information

Expand Down
19 changes: 19 additions & 0 deletions benchmarking/string-search/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# string-search

## flamegraph

Run as follows, also works on Mac.

```
cargo flamegraph --root --flamechart --verbose --bin string-search-heaptrack
```

This example runs 1 Million invocations of `Entries::search()`

<img src="./flamegraph.svg"/>

## heaptrack

Run `./run_heaptrack.sh`. Tested on Debian 12.

Connect to a remote host using `ssh -X` to allow forwarding `heaptrack_gui`.
Loading
Loading