hand

finger proxy server
Log | Files | Refs | README

commit cabf3698b95b22ca73ac726d90dca782ce956c1d
parent 45d6d9ea210b269ae6e9bbe860031d547618acb9
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Wed,  1 Dec 2021 23:51:36 -0800

Add hello world server

Diffstat:
MCargo.lock | 93+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
MCargo.toml | 2++
Msrc/main.rs | 23++++++++++++++++++++++-
3 files changed, 117 insertions(+), 1 deletion(-)

diff --git a/Cargo.lock b/Cargo.lock @@ -3,6 +3,32 @@ version = 3 [[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "crossbeam-channel" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06ed27e177f16d65f0f0c22a213e17c696ace5dd64b14258b52f9417ccb52db4" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d82cfc11ce7f2c3faef78d8a684447b40d503d9681acebed6cb728d45940c4db" +dependencies = [ + "cfg-if", + "lazy_static", +] + +[[package]] name = "fingers" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -13,4 +39,71 @@ name = "hand" version = "0.1.0" dependencies = [ "fingers", + "vial", +] + +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.108" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8521a1b57e76b1ec69af7599e75e38e7b7fad6610f037db8c79b127201b5d119" + +[[package]] +name = "libc-strftime" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3badb12f3d8623017f2cff9de476ff32f426ef45419253366fa088b8df6364cf" +dependencies = [ + "libc", +] + +[[package]] +name = "num_cpus" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "once_cell" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" + +[[package]] +name = "threadfin" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e27f719ae4498ad880ca2eb9ebe7d38f6d168b61f6cc0845a7422f318bbdd4e" +dependencies = [ + "crossbeam-channel", + "num_cpus", + "once_cell", +] + +[[package]] +name = "vial" +version = "0.1.11" +source = "git+https://github.com/sigaloid/vial#3dfa4959f19d149f8e7a848e672d2361b8b2b7af" +dependencies = [ + "libc-strftime", + "threadfin", ] diff --git a/Cargo.toml b/Cargo.toml @@ -7,3 +7,5 @@ edition = "2018" [dependencies] fingers = "0.1.2" +# Depends on fork, due to upstream being unmaintained +vial = {git = "https://github.com/sigaloid/vial", default-features = false} diff --git a/src/main.rs b/src/main.rs @@ -1,3 +1,24 @@ +use vial::prelude::*; + +routes! { + GET "/echo" => echo; + POST "/echo" => post; +} + +fn echo(_: Request) -> &'static str { + "<form method='POST'> + <input type='text' name='echo'/> + <input type='submit'/> + </form>" +} + +fn post(req: Request) -> String { + format!( + "<h1>You said: {}</h1>", + req.form("echo").unwrap_or("You didn't say anything!") + ) +} + fn main() { - println!("Hello, world!"); + vial::run!().unwrap(); }