From e270fbbdb5f35f9149a44e486c06f62c1cd7bcb8 Mon Sep 17 00:00:00 2001 From: "Christoph J. Scherr" Date: Thu, 15 Feb 2024 16:29:38 +0100 Subject: [PATCH] a few things --- Cargo.lock | 51 +++++++++++++++++++++++++++++ Cargo.toml | 19 +++++++++++ members/matchmatchmatch/Cargo.toml | 8 +++++ members/matchmatchmatch/src/main.rs | 16 +++++++++ members/shortc/Cargo.toml | 9 +++++ members/shortc/src/main.rs | 22 +++++++++++++ members/tokio-send-sync/Cargo.toml | 10 ++++++ members/tokio-send-sync/src/main.rs | 20 +++++++++++ 8 files changed, 155 insertions(+) create mode 100644 members/matchmatchmatch/Cargo.toml create mode 100644 members/matchmatchmatch/src/main.rs create mode 100644 members/shortc/Cargo.toml create mode 100644 members/shortc/src/main.rs create mode 100644 members/tokio-send-sync/Cargo.toml create mode 100644 members/tokio-send-sync/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index b1fa8ae..feafeec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -176,6 +176,12 @@ version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e1e5f035d16fc623ae5f74981db80a439803888314e3a555fd6f04acd51a3205" +[[package]] +name = "bytes" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" + [[package]] name = "cast" version = "0.3.0" @@ -840,6 +846,10 @@ version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" +[[package]] +name = "matchmatchmatch" +version = "0.1.0" + [[package]] name = "memchr" version = "2.7.1" @@ -861,6 +871,17 @@ dependencies = [ "adler", ] +[[package]] +name = "mio" +version = "0.8.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f3d0b296e374a4e6f3c7b0a1f5a51d748a0d34c85e7dc48fc3fa9a87657fe09" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + [[package]] name = "nom" version = "7.1.3" @@ -1288,6 +1309,13 @@ dependencies = [ "digest", ] +[[package]] +name = "shortc" +version = "0.1.0" +dependencies = [ + "anyhow", +] + [[package]] name = "slab" version = "0.4.9" @@ -1331,6 +1359,16 @@ checksum = "b7c388c1b5e93756d0c740965c41e8822f866621d41acbdf6336a6a168f8840c" name = "socker" version = "0.1.0" +[[package]] +name = "socket2" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9" +dependencies = [ + "libc", + "windows-sys 0.48.0", +] + [[package]] name = "strsim" version = "0.10.0" @@ -1450,9 +1488,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c89b4efa943be685f629b149f53829423f8f5531ea21249408e8e2f8671ec104" dependencies = [ "backtrace", + "bytes", + "libc", + "mio", "num_cpus", "pin-project-lite", + "socket2", "tokio-macros", + "windows-sys 0.48.0", ] [[package]] @@ -1466,6 +1509,14 @@ dependencies = [ "syn 2.0.48", ] +[[package]] +name = "tokio-send-sync" +version = "0.1.0" +dependencies = [ + "anyhow", + "tokio", +] + [[package]] name = "tokryon" version = "0.0.0" diff --git a/Cargo.toml b/Cargo.toml index 1847b58..f682855 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,14 +7,18 @@ members = [ "members/pest-demo", "members/revsqrt", "members/serde-json-demo", + "members/shortc", "members/slog-demo", "members/socker", "members/tokryon", + "members/tokio-send-sync", + "members/matchmatchmatch", ] default-members = [ ".", "members/revsqrt", "members/criterion-demo", + "members/shortc", "members/pest-demo", "members/serde-json-demo", "members/slog-demo", @@ -22,8 +26,23 @@ default-members = [ "members/panic-calm", "members/socker", "members/tokryon", + "members/tokio-send-sync", + "members/matchmatchmatch", ] +[workspace.dependencies] +anyhow = "1.0.79" +thiserror = "1.0.56" +tokio = { version = "1.35.1", features = [ + "net", + "rt", + "macros", + "rt-multi-thread", + "io-util", + "time", + "sync", +] } + [package] name = "rs-basic" version = "0.2.1" diff --git a/members/matchmatchmatch/Cargo.toml b/members/matchmatchmatch/Cargo.toml new file mode 100644 index 0000000..4c80931 --- /dev/null +++ b/members/matchmatchmatch/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "matchmatchmatch" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/members/matchmatchmatch/src/main.rs b/members/matchmatchmatch/src/main.rs new file mode 100644 index 0000000..2b38896 --- /dev/null +++ b/members/matchmatchmatch/src/main.rs @@ -0,0 +1,16 @@ +fn main() { + let deep_type = Option::Some(Option::Some(Option::Some(()))); + match deep_type { + Some(inner) => match inner { + Some(inner) => match inner { + Some(inner) => { + println!("{:?}", inner); return; + } + None => {} + }, + None => {} + }, + None => {} + } + unreachable!() +} diff --git a/members/shortc/Cargo.toml b/members/shortc/Cargo.toml new file mode 100644 index 0000000..cc906d5 --- /dev/null +++ b/members/shortc/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "shortc" +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 } diff --git a/members/shortc/src/main.rs b/members/shortc/src/main.rs new file mode 100644 index 0000000..4da3f9b --- /dev/null +++ b/members/shortc/src/main.rs @@ -0,0 +1,22 @@ +use anyhow::Result; +use std::{ + io::{self, prelude::*}, + net, +}; + +// This is just a very simple tcp server/client that connects to itself + +const ADDR: &'static str = "127.0.0.1:9911"; + +fn main() -> Result<()> { + let mut listen = net::TcpListener::bind(ADDR)?; + let mut client = net::TcpStream::connect(ADDR)?; + let mut sink = io::sink(); + client.write_all(b"foo")?; + let mut com = listen.accept()?; + com.0.write_all(b"bak")?; + let mut buf = [0;3]; + client.read(&mut buf)?; + println!("{buf:x?}"); + Ok(()) +} diff --git a/members/tokio-send-sync/Cargo.toml b/members/tokio-send-sync/Cargo.toml new file mode 100644 index 0000000..095c99f --- /dev/null +++ b/members/tokio-send-sync/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "tokio-send-sync" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +tokio.workspace = true +anyhow.workspace = true diff --git a/members/tokio-send-sync/src/main.rs b/members/tokio-send-sync/src/main.rs new file mode 100644 index 0000000..6ab531a --- /dev/null +++ b/members/tokio-send-sync/src/main.rs @@ -0,0 +1,20 @@ +use std::{ sync::Arc}; + +use tokio::{net::TcpListener, sync::Mutex}; + +type TestType = u64; + +async fn foo(t: TestType) -> Result { + println!("{t}"); + TcpListener::bind("127.0.0.1:50023").await +} + +#[tokio::main()] +async fn main() { + let testdata: TestType = 1337; + let arcmut = Arc::new(Mutex::new(testdata)); + tokio::spawn(async move { + let a = foo(testdata).await; + a.unwrap().accept().await + }); +}