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

Cargo make build failing #311

Open
RyanJesky opened this issue Aug 25, 2022 · 6 comments
Open

Cargo make build failing #311

RyanJesky opened this issue Aug 25, 2022 · 6 comments

Comments

@RyanJesky
Copy link

When running Cargo make build, the build is failing due to the following error. This may not be the place to resolve this but I have looked all over and I do not see anybody discussing this. Please advise:

error[E0283]: type annotations needed for Closure<T>
--> C:\Users\Me.cargo\registry\src\github.com-1ecc6299db9ec823\seed-0.6.0\src\browser\service\routing.rs:113:9
|
113 | let closure = Closure::new(move |event: web_sys::Event| {
| ^^^^^^^
|
= note: cannot satisfy _: WasmClosure
note: required by a bound in Closure::<T>::new
--> C:\Users\Me.cargo\registry\src\github.com-1ecc6299db9ec823\wasm-bindgen-0.2.82\src\closure.rs:251:17
|
251 | T: ?Sized + WasmClosure,
| ^^^^^^^^^^^ required by this bound in Closure::<T>::new
help: consider giving closure an explicit type, where the type for type parameter T is specified
|
113 | let closure: Closure = Closure::new(move |event: web_sys::Event| {
| ++++++++++++
help: consider specifying the type argument in the function call
|
113 | let closure = Closure::new::(move |event: web_sys::Event| {
| +++++

error[E0283]: type annotations needed for Closure<T>
--> C:\Users\Me.cargo\registry\src\github.com-1ecc6299db9ec823\seed-0.6.0\src\browser\service\routing.rs:113:9
|
113 | let closure = Closure::new(move |event: web_sys::Event| {
| ^^^^^^^
|
= note: multiple impls satisfying [closure@C:\Users\Me\.cargo\registry\src\github.com-1ecc6299db9ec823\seed-0.6.0\src\browser\service\routing.rs:113:32: 150:6]: IntoWasmClosure<_> found in the wasm_bindgen crate:
- impl<T, A, R> IntoWasmClosure<(dyn Fn(A) -> R + 'static)> for T
where <T as FnOnce<(A,)>>::Output == R, T: 'static, T: Fn<(A,)>, A: 'static, A: FromWasmAbi, R: 'static, R: ReturnWasmAbi;
- impl<T, A, R> IntoWasmClosure<(dyn FnMut(A) -> R + 'static)> for T
where <T as FnOnce<(A,)>>::Output == R, T: 'static, T: FnMut<(A,)>, A: 'static, A: FromWasmAbi, R: 'static, R: ReturnWasmAbi;
note: required by a bound in Closure::<T>::new
--> C:\Users\Me.cargo\registry\src\github.com-1ecc6299db9ec823\wasm-bindgen-0.2.82\src\closure.rs:271:12
|
271 | F: IntoWasmClosure + 'static,
| ^^^^^^^^^^^^^^^^^^ required by this bound in Closure::<T>::new
help: consider giving closure an explicit type, where the type for type parameter T is specified
|
113 | let closure: Closure = Closure::new(move |event: web_sys::Event| {
| ++++++++++++
help: consider specifying the type argument in the function call
|
113 | let closure = Closure::new::(move |event: web_sys::Event| {
| +++++

For more information about this error, try rustc --explain E0283.
error: could not compile seed due to 2 previous errors
[cargo-make] ERROR - Error while executing command, exit code: 101
[cargo-make] WARN - Build Failed.

@theGunner295
Copy link

theGunner295 commented Oct 1, 2022

Receiving a very similar issue when building...
Note that this is when running cargo make build in src/main/webapp

Error Link

On Aiode Dev branch 2.1

@Kryod
Copy link

Kryod commented Oct 1, 2022

Same issue

@robinfriedli
Copy link
Owner

Would likely have to update seed but since the webapp is barely a demo it's not a priority right now. When I do continue working on the webapp, which I have no plans for right now, I might switch to a different technology entirely anyway.

@Snider
Copy link

Snider commented Oct 25, 2022

Would likely have to update seed but since the webapp is barely a demo it's not a priority right now. When I do continue working on the webapp, which I have no plans for right now, I might switch to a different technology entirely anyway.

Could you update the readme for the main branch?

@chiraitori
Copy link

fix the routing.rs then it will work

use super::super::{
    url,
    util::{self, ClosureNew},
    Url,
};
use std::convert::{identity, TryFrom, TryInto};
use wasm_bindgen::{closure::Closure, JsCast, JsValue};

/// Add a new route using history's `push_state` method.
///
/// # References
/// * [MDN docs](https://developer.mozilla.org/en-US/docs/Web/API/History_API)
pub fn push_route<U: Into<Url>>(url: U) -> Url {
    let url = url.into();
    let data = JsValue::from_str(&serde_json::to_string(&url).expect("Problem serializing route data"));

    let title = match &url.title {
        Some(t) => t,
        None => "",
    };

    let mut path = String::from("/") + &url.path.join("/");
    if let Some(search) = &url.search {
        path = path + "?" + search;
    }

    if let Some(hash) = &url.hash {
        path = path + "#" + hash;
    }

    util::history()
        .push_state_with_url(&data, title, Some(&path))
        .expect("Problem pushing state");
    url
}

pub fn setup_popstate_listener<Ms>(
    update: impl Fn(Ms) + 'static,
    updated_listener: impl Fn(Closure<dyn FnMut(web_sys::Event)>) + 'static,
    routes: fn(Url) -> Option<Ms>,
) where
    Ms: 'static,
{
    let closure: Closure<dyn FnMut(web_sys::Event)> = Closure::new(move |ev: web_sys::Event| {
        let ev = ev
            .dyn_ref::<web_sys::PopStateEvent>()
            .expect("Problem casting as Popstate event");

        let url = match ev.state().as_string() {
            Some(state_str) => serde_json::from_str(&state_str).expect("Problem deserializing popstate state"),
            None => url::current(),
        };

        if let Some(routing_msg) = routes(url) {
            update(routing_msg);
        }
    });

    (util::window().as_ref() as &web_sys::EventTarget)
        .add_event_listener_with_callback("popstate", closure.as_ref().unchecked_ref())
        .expect("Problem adding popstate listener");

    updated_listener(closure);
}

pub fn setup_hashchange_listener<Ms>(
    update: impl Fn(Ms) + 'static,
    updated_listener: impl Fn(Closure<dyn FnMut(web_sys::Event)>) + 'static,
    routes: fn(Url) -> Option<Ms>,
) where
    Ms: 'static,
{
    let closure: Closure<dyn FnMut(web_sys::Event)> = Closure::new(move |ev: web_sys::Event| {
        let ev = ev
            .dyn_ref::<web_sys::HashChangeEvent>()
            .expect("Problem casting as hashchange event");

        let url: Url = ev
            .new_url()
            .try_into()
            .expect("cast hashchange event url to `Url`");

        if let Some(routing_msg) = routes(url) {
            update(routing_msg);
        }
    });

    (util::window().as_ref() as &web_sys::EventTarget)
        .add_event_listener_with_callback("hashchange", closure.as_ref().unchecked_ref())
        .expect("Problem adding hashchange listener");

    updated_listener(closure);
}

#[allow(clippy::option_map_unit_fn)]
pub fn setup_link_listener<Ms>(update: impl Fn(Ms) + 'static, routes: fn(Url) -> Option<Ms>)
where
    Ms: 'static,
{
    let closure: Closure<dyn FnMut(web_sys::Event)> = Closure::new(move |event: web_sys::Event| {
        if let Some(href_el) = event
            .target()
            .and_then(|et| et.dyn_into::<web_sys::Element>().ok())
            .and_then(|el| el.closest("[href]").ok())
        {
            if let Some(Ok(href)) = href_el.and_then(|el| Some(Ok::<_, JsValue>(el.get_attribute("href").unwrap())))
            {
                if href.is_empty() {
                    event.prevent_default(); // Prevent page refresh
                } else {
                    let url = Url::try_from(href).expect("cast link href to `Url`");
                    if let Some(redirect_msg) = routes(url.clone()) {
                        push_route(url);
                        event.prevent_default(); // Prevent page refresh
                        update(redirect_msg);
                    }
                }
            }
        }
    });

    (util::document().as_ref() as &web_sys::EventTarget)
        .add_event_listener_with_callback("click", closure.as_ref().unchecked_ref())
        .expect("Problem setting up link interceptor");

    closure.forget();
}




#[cfg(test)]
mod tests {
    use wasm_bindgen_test::*;

    use super::*;

    wasm_bindgen_test_configure!(run_in_browser);

    #[wasm_bindgen_test]
    fn parse_url_simple() {
        let expected = Url {
            path: vec!["path1".into(), "path2".into()],
            hash: None,
            search: None,
            title: None,
        };

        let actual: Url = "/path1/path2".to_string().try_into().unwrap();
        assert_eq!(expected, actual)
    }

    #[wasm_bindgen_test]
    fn parse_url_with_hash_search() {
        let expected = Url {
            path: vec!["path".into()],
            hash: Some("hash".into()),
            search: Some("search=query".into()),
            title: None,
        };

        let actual: Url = "/path?search=query#hash".to_string().try_into().unwrap();
        assert_eq!(expected, actual)
    }

    #[wasm_bindgen_test]
    fn parse_url_with_hash_only() {
        let expected = Url {
            path: vec!["path".into()],
            hash: Some("hash".into()),
            search: None,
            title: None,
        };

        let actual: Url = "/path#hash".to_string().try_into().unwrap();
        assert_eq!(expected, actual)
    }

    #[wasm_bindgen_test]
    fn parse_url_with_hash_routing() {
        let expected = Url {
            path: vec!["".into()],
            hash: Some("/discover".into()),
            search: None,
            title: None,
        };

        let actual: Url = "/#/discover".to_string().try_into().unwrap();
        assert_eq!(expected, actual)
    }
}

@robinfriedli
Copy link
Owner

routing.rs is not my code, it's from the seed framework. Simply updating the dependency would probably be enough to fix it, the webapp hasn't been touched in years. Howver, I'm more likely to just remove it from the master branch entirely. It got merged into master with the other development/v2.0 stuff in a demo state and I currently have no plans to continue working on it

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

6 participants