Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Examples don't work #127

Open
benkeil opened this issue Sep 19, 2023 · 2 comments
Open

Examples don't work #127

benkeil opened this issue Sep 19, 2023 · 2 comments

Comments

@benkeil
Copy link

benkeil commented Sep 19, 2023

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
Copy link
Contributor

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
Copy link

BrittonR commented Feb 9, 2024

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants