lunatic-solutions / submillisecond

A lunatic web framework
MIT License
912 stars 18 forks source link

Examples don't work #127

Open benkeil opened 1 year ago

benkeil commented 1 year ago
use std::io::Result;
use submillisecond::extract::Path;
use submillisecond::{router, Application, NamedParam};

fn main() -> Result<()> {
    Application::new(router! {
        GET "/" => index
        GET "/:name" => hi
        GET "/:name/:age" => hi_2
        GET "/users/:first/:last/:age" => greet
    })
    .serve("0.0.0.0:3000")
}

fn index() -> &'static str {
    "Hello :)"
}

#[derive(NamedParam)]
#[param(name = "name")]
struct HiParams(String);

fn hi(HiParams(name): HiParams) -> String {
    format!("Hi {}!", name)
}

fn hi_2(Path((name, age)): Path<(String, String)>) -> String {
    format!("Hi {}({})!", name, age)
}

#[derive(NamedParam)]
struct GreetInfo {
    first: String,
    last: String,
    age: u32,
}

fn greet(GreetInfo { first, last, age }: GreetInfo) -> String {
    format!("Welcome {first} {last}. You are {age} years old.")
}

http://localhost:3000/users/1/2/3 => Welcome 1 2. You are 1 years old.

http://localhost:3000/1/2/

thread '<unnamed>' panicked at 'called `Option::unwrap()` on a `None` value', /Users/ben/.cargo/registry/src/index.crates.io-6f17d22bba15001f/submillisecond-0.4.1/src/extract/path.rs:156:14
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
[2023-09-19T19:52:41Z WARN  lunatic_process] Process 14 failed, notifying: 1 links
                    (Set ENV variable `RUST_LOG=lunatic=debug` to show stacktrace)
INFO submillisecond::supervisor: GET /1/2/    -
ERROR submillisecond::supervisor: Worker process panicked

It's also not possible to create NamedParam with only one param.

The configuration in the Cargo.toml also don't work. When running cargo build --target=wasm32-wasi everything works fine.

[package]
name = "playground"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
name = "playground"
path = "src/lib.rs"

[build]
target = "wasm32-wasi"

[target.wasm32-wasi]
runner = "lunatic"

[dependencies]
submillisecond = "0.4.1"
submillisecond-live-view = "0.4.1"
serde = "1.0.188"
serde_json = "1.0.107"

But cargo build fails.

ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
bkolobara commented 1 year ago

Thanks for testing this. The route matching seems to be messed up, I will have a look at it.

The configuration in the Cargo.toml also don't work. When running cargo build --target=wasm32-wasi everything works fine.

The [build] and [target.wasm32-wasi] sections go into the .cargo/config.toml file, like here, not into the Cargo.toml. That's why it's failing.

BrittonR commented 9 months ago

@bkolobara were you ever able to look into this? I'm still running into this problem with Structs with a non String Type included and all Tuples provided to Path