mpsc and mermaid test
cargo devel CI / cargo CI (push) Has been cancelled Details

This commit is contained in:
Christoph J. Scherr 2024-03-04 12:17:55 +01:00
parent 2a2dc41446
commit 5e0f587363
Signed by: cscherrNT
GPG Key ID: 8E2B45BC51A27EA7
5 changed files with 54 additions and 0 deletions

7
Cargo.lock generated
View File

@ -897,6 +897,13 @@ dependencies = [
"anyhow", "anyhow",
] ]
[[package]]
name = "mpsc-full"
version = "0.1.0"
dependencies = [
"anyhow",
]
[[package]] [[package]]
name = "nom" name = "nom"
version = "7.1.3" version = "7.1.3"

View File

@ -15,11 +15,13 @@ members = [
"members/matchmatchmatch", "members/matchmatchmatch",
"members/future_stream", "members/future_stream",
"members/mpsc", "members/mpsc",
"members/mpsc-full",
] ]
default-members = [ default-members = [
".", ".",
"members/revsqrt", "members/revsqrt",
"members/mpsc", "members/mpsc",
"members/mpsc-full",
"members/criterion-demo", "members/criterion-demo",
"members/shortc", "members/shortc",
"members/pest-demo", "members/pest-demo",

View File

@ -3,6 +3,11 @@
This project contains various smaller rust projects, often made by myself to This project contains various smaller rust projects, often made by myself to
gain more understanding with a topic or dependency. gain more understanding with a topic or dependency.
```mermaid
graph TD
Start --> End
```
## Rust unsafe ## Rust unsafe
Unsafe rust offers many possibilities otherwise locked from rust, which might Unsafe rust offers many possibilities otherwise locked from rust, which might

View File

@ -0,0 +1,9 @@
[package]
name = "mpsc-full"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
anyhow.workspace = true

View File

@ -0,0 +1,31 @@
//! what happens when we send a lot of items to an mpsc?
use std::{
sync::{mpsc, Barrier},
thread,
};
const NUMS: &[u8] = &[1, 3, 3, 7, 0xd, 0xe, 0xa, 0xd, 0xb, 0xe, 0xe, 0xf];
fn main() -> anyhow::Result<()> {
let (sender, receiver) = mpsc::channel();
for n in NUMS {
sender.send(n).unwrap();
}
drop(sender);
let mut collect = Vec::new();
while let Ok(n) = receiver.recv() {
collect.push(*n);
}
for i in NUMS {
assert!(collect.contains(i))
}
println!("it stores the values, even when the sender is dropped");
Ok(())
}