-
Notifications
You must be signed in to change notification settings - Fork 24
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
Type error when using picoserve::routing::Router::nest
#49
Comments
There is indeed a bug! Good find! I unfortunately don't have time to do a proper patch and release, but I've committed the fix to I also suggest you change your
|
Thank you for the fix! It's working perfectly now - don't worry about the patch/release, take your time :) I tried to change the return types, however since I'm using embassy, it needs a concrete type signature, so I kept the pub type AppRouter = impl picoserve::routing::PathRouter<GlobalState> annotation for the Should I close the issue, or should that be done when the release is out? |
picoserve::routing::Router::nest
/ possible bugpicoserve::routing::Router::nest
I'll close the issue when the release is out. |
@Sycrosity which version of the Rust compiler are you using and how do you pass the
Any ideas? |
I'm using version 1.80.0-nightly (the espup toolchain for esp32 devices) I passed it like this: pub type AppRouter = impl picoserve::routing::PathRouter<GlobalState>;
#[task(pool_size = WEB_TASK_POOL_SIZE)]
pub async fn site_task(
id: usize,
// uuid: Uuid,
stack: &'static Stack<WifiDevice<'static, WifiApDevice>>,
app: &'static picoserve::Router<AppRouter, GlobalState>,
config: &'static picoserve::Config<Duration>,
state: GlobalState,
) -> ! {
..... I'd likely need to see an example of your code or a repo link to see what you may have done differently. |
Thanks! |
@JuliDi I'm a bit confused as to what pub fn app_router() -> picoserve::Router<AppRouter, GlobalState> {
picoserve::Router::from_service(NotFound)
.route(
"/",
get_service(picoserve::response::File::html(include_str!(
"../dist/index.html"
))),
)
.route(
"/favicon.svg",
get_service(picoserve::response::File::with_content_type(
"text/plain; charset=utf-8",
include_str!("../dist/favicon.svg").as_bytes(),
)),
)
.nest("/api", api_router())
} |
No special reason, I may have forgotten to revert some changes as I kept editing due to the overwhelming number of errors with opaque type stuff... Btw, what is your GlobalState? Thanks for the example, I'll give it a try. Also, is there a way to use picoserve without nightly features? I feel like these things might break more often in the future. |
GlobalState is pub struct GlobalState {
pub wifi_creds: WifiCredentialsState,
}
...
pub struct WifiCredentialsState(pub &'static Mutex<CriticalSectionRawMutex, WifiCredentials>);
...
pub struct WifiCredentials {
ssid: heapless::String<32>,
password: heapless::String<64>,
} I am also on the latest version of embassy so I don't believe that is it either |
Interesting, thanks! I will give it a try next week. Probably some rather trivial mistake after all... |
On rust version 1.81.0, I now have this error too - seems to be due to something in rust 1.81.0 |
I feel rather stupid - sammhicks' initial suggestion was all that was needed, with no |
What do you mean? Apparently this is a problem with the new TAIT requirements |
I've been battling this for a while - using 1.80.0-nightly has resolved the issue, but with anything later I'm encountering this error. |
As suggested on the Embassy Matrix chat, you need to wrap the type into in its own module like so mod approuter {
use picoserve::routing::get;
pub struct GlobalState {
pub led_on: bool,
}
pub type AppRouter = impl picoserve::routing::PathRouter<GlobalState>;
pub fn make_app() -> picoserve::Router<AppRouter, GlobalState> {
picoserve::Router::new().route("/", get(|| async move { "Hello World" }))
}
}
// and then use it like this e.g.
#[embassy_executor::task(pool_size = WEB_TASK_POOL_SIZE)]
async fn web_task(
id: usize,
stack: &'static embassy_net::Stack<Device<'static>>,
app: &'static picoserve::Router<approuter::AppRouter, approuter::GlobalState>,
config: &'static picoserve::Config<Duration>,
state: approuter::GlobalState,
) -> ! {
//... |
While attempting to nest a router like so: (simplified example)
I encountered the following error:
which happens regardless of if the
impl picoserve::routing::PathRouter<GlobalState>
is different for each router or not.Is this a bug, and if not what have I done wrong here? an example of how to use nesting could be useful to work out what should be done instead.
Amazing project btw!
The text was updated successfully, but these errors were encountered: