diff --git a/Cargo.lock b/Cargo.lock index 6a9cacf..b0faa35 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -906,9 +906,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "toad" -version = "1.0.0-beta.2" +version = "1.0.0-beta.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d41fbfaadd52558c4d595bf38fb6942333307c47158abc30c0c3a0bbd1848b65" +checksum = "7680b4a4868e2527ee0cb58b3850179f9ad9a44532b13fb9e4487a176091b71a" dependencies = [ "embedded-time", "log", @@ -922,7 +922,7 @@ dependencies = [ "serde", "serde_json", "tinyvec", - "toad-array", + "toad-array 0.8.0", "toad-hash", "toad-len", "toad-macros", @@ -943,6 +943,16 @@ dependencies = [ "toad-len", ] +[[package]] +name = "toad-array" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90c89c65763a9ed217a09ea4f43615153e9bccf82f972f3e5914ded7f5658fe6" +dependencies = [ + "tinyvec", + "toad-len", +] + [[package]] name = "toad-cursor" version = "0.2.0" @@ -990,13 +1000,13 @@ dependencies = [ [[package]] name = "toad-msg" -version = "0.18.1" +version = "1.0.0-beta.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d78ad790094eefd8146fab35178e23b224285fe9b275132a31872c0f74b1a8ff" +checksum = "63f5ff0cb4b95ec5eb83db517a2301d6a5a5917d94124140dff2fafa283a41f5" dependencies = [ "blake2", "tinyvec", - "toad-array", + "toad-array 0.8.0", "toad-cursor", "toad-hash", "toad-len", @@ -1017,7 +1027,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fdad9197bf6974091949a6d3e00946558d69e0d7b3d159283c6c43fffdef59dc" dependencies = [ "tinyvec", - "toad-array", + "toad-array 0.2.3", "toad-len", "toad-writable", ] @@ -1028,7 +1038,7 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ebe82c1076c85774b389e86cb2a2dbb846e35e599e9b42c8f2fc6628593cd0a9" dependencies = [ - "toad-array", + "toad-array 0.2.3", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 770776a..b6350a1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,8 +5,8 @@ edition = "2021" publish = false [dependencies] -toad = "1.0.0-beta.2" -toad-msg = "0.18.1" +toad = "1.0.0-beta.3" +toad-msg = "1.0.0-beta.1" simple_logger = "4.2" nb = "1.1.0" serde = {version = "1", features = ["derive"]} diff --git a/src/main.rs b/src/main.rs index 9f56429..90f6161 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,8 @@ use toad::net::Addrd; use toad::platform::Platform as _; use toad::req::Req; use toad::resp::Resp; +use toad_msg::alloc::Message; +use toad_msg::Type; mod app; mod hashed_text; @@ -82,7 +84,7 @@ struct Foo { id: String, } -fn handle_request(req: Addrd>) -> Result>, String> { +fn handle_request(req: Addrd>) -> Result, String> { let path = req.data() .path() .map_err(|e| format!("{e:?}")) @@ -94,9 +96,12 @@ fn handle_request(req: Addrd>) -> Result>, String> let mut path_segments = path_segments.clone(); path_segments.next(); let _id = path_segments.next(); + let msg = Message::builder(Type::Ack, toad::resp::code::NOT_FOUND).build(); + Ok(Addrd(msg, req.addr())) + } else { + let msg = Message::builder(Type::Ack, toad::resp::code::NOT_FOUND).build(); + Ok(Addrd(msg, req.addr())) } - - Ok(req.map(|r| Resp::for_request(&r).unwrap())) } fn server_worker(p: &'static Toad) { diff --git a/src/user.rs b/src/user.rs index 05478bb..ad43bbd 100644 --- a/src/user.rs +++ b/src/user.rs @@ -222,29 +222,33 @@ mod tests { #[test] fn user_repo_insert() { - let client = - || Client::<()> { state: Box::new(vec![UserTag::from("foo")]), - query_one: Box::new(|c, q, ps| { - assert_eq!(q.unwrap_str(), - format!( - "insert into public.usr + let client = || Client::<()> { state: Box::new(vec![UserTag::from("foo")]), + query_one: Box::new(|c, q, ps| { + assert_eq!( + q.unwrap_str(), + format!( + "insert into public.usr (tag, password, email) values ($2, $3, $4) -returning uid;")); +returning uid;" + ) + ); - let tags = c.state_mut::>(); + let tags = c.state_mut::>(); - let tag = UserTag::from(from_sql_owned::(ps[0])); + let tag = UserTag::from(from_sql_owned::(ps[0])); - if tags.contains(&tag) { - Err(()) - } else { - tags.push(tag); - Ok(Row::new(vec![("", Type::TEXT)]).value(Type::TEXT, tags.len().to_string())) - } - }), - ..Client::default() }; + if tags.contains(&tag) { + Err(()) + } else { + tags.push(tag); + Ok(Row::new(vec![("", Type::TEXT)]).value(Type::TEXT, + tags.len() + .to_string())) + } + }), + ..Client::default() }; let db = PostgresImpl::try_new(|| Ok(client()), 1).unwrap();