yew_form icon indicating copy to clipboard operation
yew_form copied to clipboard

Why is get_mut_unchecked required?

Open BafDyce opened this issue 5 years ago • 15 comments

Form::state_mut() (see below) calls RC::get_mut_unchecked which is unsafe and nightly only. Unfortunately, it is not documented why this is necessary (and why Rc::get_mut() cannot be used instead). Changing this would allow us to remove the feature requirement. As a result, it would be possible to compile yew_form on stable Rust.

https://github.com/jfbilodeau/yew_form/blob/afd25efe8bd367ffc5fb15e65aae1afce0af5e17/yew_form/src/form.rs#L24-L28

BafDyce avatar Mar 21 '20 09:03 BafDyce

Done. Thanks!

jfbilodeau avatar Jul 16 '20 13:07 jfbilodeau

@jfbilodeau Why is the feature requirement stilll there? https://github.com/jfbilodeau/yew_form/blob/5ce6bf65e400258ff0d3483df82d0cf17b0a45e5/yew_form/src/lib.rs#L1 Currently I am not able to compile this on stable rust.

L0g4n avatar Sep 02 '20 11:09 L0g4n

Thanks for the heads up @L0g4n . My oversight. I remove the offending line and updated the crate. Please let me know if it compiles successfully for you.

jfbilodeau avatar Sep 02 '20 12:09 jfbilodeau

@jfbilodeau Thanks. I apologize if I sounded a bit harsh, I really appreciate your work here.

L0g4n avatar Sep 02 '20 12:09 L0g4n

@L0g4n: No offence taken. I appreciate the correction.

jfbilodeau avatar Sep 02 '20 13:09 jfbilodeau

@jfbilodeau Sorry to bother again, but when I try to reproduce your form example I now get panicked at 'called `Option::unwrap()` on a `None` value', ~\.cargo\registry\src\github.com-1ecc6299db9ec823\yew_form-0.1.7\src\form.rs:24:39 from your most recent commit. This happens as soon as the oninput callback from the form is called, i.e. I type some sample text and then the panic happens.

L0g4n avatar Sep 02 '20 16:09 L0g4n

Hey @L0g4n, I'm having a hard time reproducing the problem at my end. Any chance you could send me a bit more details? Platform? How are you running the app? Anything else? Thanks!

jfbilodeau avatar Sep 03 '20 10:09 jfbilodeau

Sure, I hope this is a minimal reproducible example: https://gist.github.com/L0g4n/aa943183eff937cfb90865563a03fe2a Platform: x86_64-pc-windows-msvc Edit: I am running the app via yarn, with the rust webpack plugin.

L0g4n avatar Sep 03 '20 10:09 L0g4n

@jfbilodeau Could you reproduce the unwrap error with the code submitted in the gist or do you need more information?

L0g4n avatar Sep 05 '20 12:09 L0g4n

@L0g4n: Working on it. Any chance you could share with me your cargo.toml and lib.rs?

jfbilodeau avatar Sep 05 '20 22:09 jfbilodeau

Sure.


[lib]
crate-type = ["cdylib", "rlib"]

[features]
default = ["wee_alloc"]

[dependencies]
yew = "0.17.3"
wasm-bindgen = "0.2.67"
wee_alloc = { version = "0.4.5", optional = true }
log = "0.4.11"
wasm-logger = "0.2.0"
console_error_panic_hook = "0.1.6"
anyhow = "1.0.32"
serde = { version = "1.0", features = ["derive"] }
# validator backend for `yew_form`
validator = { version = "0.10" }
validator_derive = "0.10"
yew_form = "0.1"
yew_form_derive = "0.1"

[dev-dependencies]
wasm-bindgen-test = "0.3"

lib.rs:


#![recursion_limit = "512"]

use wasm_bindgen::prelude::*;

mod api;
mod app;
mod models;
mod view;

// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
// allocator.
#[cfg(feature = "wee_alloc")]
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;

/// This is the entry point for the web app
#[wasm_bindgen]
pub fn run_app() {
    wasm_logger::init(wasm_logger::Config::default());

    // eases debugging by forwarding panic messages to the web console in debug mode
    #[cfg(debug_assertions)]
    console_error_panic_hook::set_once();

    yew::start_app::<view::Home>();
}

L0g4n avatar Sep 05 '20 22:09 L0g4n

Hey @L0g4n, sorry to bother you but I'm having trouble reproducing the crash with the code segments you provided. I hate to be a pain, but is there any chance you could privately share the full codebase to build and reproduce?

jfbilodeau avatar Sep 08 '20 10:09 jfbilodeau

No problem, the frontend at this point in time is not that advanced. I have sent you an email with the source code. At this point I suspect that I am doing something unexpected with your library and this is why I get an unwrap traceback.

L0g4n avatar Sep 08 '20 11:09 L0g4n

@jfbilodeau OK, so because I suspected an error from my side I just checked out this repo and built the example. Now: I get the same error here, as soon as I enter something in the form. image

L0g4n avatar Sep 08 '20 14:09 L0g4n

@L0g4n: Sorry, your issue slipped betweens the cracks. It should now be solved.

jfbilodeau avatar Jan 08 '21 14:01 jfbilodeau