Open Sycrosity opened 2 months ago
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 nest_fix
.
I also suggest you change your app_router
and api_router
functions to have a return type of
picoserve::Router<impl picoserve::routing::PathRouter<GlobalState>, GlobalState>
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 app_router
, but changed it for the api_router
.
Should I close the issue, or should that be done when the release is out?
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 pub type AppRouter
into embassy task arguments?
I can't get rid of errors like
error: item does not constrain `AppRouter::{opaque#0}`, but has it in its signature
--> src/main.rs:54:1
|
54 | #[embassy_executor::task(pool_size = WEB_TASK_POOL_SIZE)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: consider moving the opaque type's declaration and defining uses into a separate module
Any ideas? I'm using the latest versions of rustc nightly, embassy and the nest_fix branch of this crate.
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! I will give it a try later, maybe I can get it to work with what you shared (first of all, I should use the same toolchain to avoid other possibly breaking changes on nightly). I've also uploaded the current main.rs here https://gist.github.com/JuliDi/284280e4b702cafda70e76f9c8ee406a if you want to have a look.
@JuliDi I'm a bit confused as to what MyRouter
is on lines 150-153. In my equivalent of the make_app
function, I have this:
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. But I am unsure whether it solves the opaque type errors. Maybe this is also caused by newer versions of embassy? Which one are you using?
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...
@Sycrosity which version of the Rust compiler are you using and how do you pass the
pub type AppRouter
into embassy task arguments? I can't get rid of errors likeerror: item does not constrain `AppRouter::{opaque#0}`, but has it in its signature --> src/main.rs:54:1 | 54 | #[embassy_executor::task(pool_size = WEB_TASK_POOL_SIZE)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: consider moving the opaque type's declaration and defining uses into a separate module
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 type State = ...
needed at all.
What do you mean? Apparently this is a problem with the new TAIT requirements
@Sycrosity which version of the Rust compiler are you using and how do you pass the
pub type AppRouter
into embassy task arguments? I can't get rid of errors likeerror: item does not constrain `AppRouter::{opaque#0}`, but has it in its signature --> src/main.rs:54:1 | 54 | #[embassy_executor::task(pool_size = WEB_TASK_POOL_SIZE)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: consider moving the opaque type's declaration and defining uses into a separate module
On rust version 1.81.0, I now have this error too - seems to be due to something in rust 1.81.0
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!