Skip to content

Examples don't work #127

@benkeil

Description

@benkeil
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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions