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

Closure support #8

Open
hajifkd opened this issue Apr 13, 2017 · 1 comment
Open

Closure support #8

hajifkd opened this issue Apr 13, 2017 · 1 comment

Comments

@hajifkd
Copy link
Owner

hajifkd commented Apr 13, 2017

Something like this;

impl<A, B> JSSerialize for Box<Box<Fn(A) -> B>> where A: JSDeserialize, B: JSSerialize {
    fn serialize(&self) -> EM_GENERIC_WIRE_TYPE {
        // equivalent for Module.helper_vi.bind(Module, Box::into_raw(Box::new(*self)))...
    }
}

We may well need JSSerializeOnce (JSSerializeFunc?)

pub trait JSSerializeOnce: JSID {
    fn serialize(self) -> EM_GENERIC_WIRE_TYPE;
}

since either into_raw or new consumes the pointer and Clone may not be used.
Inside args! macro, we can use a kind of duck typing with JSSerializeOnce.
Or, something like

macro_rules! jsfn {
    ( $func:expr ) => {{
        let boxed = Box::new(Box::new($func));
        Val::new(boxed.serialize());
    }}
}
...
jsfn!(|x| x + 10)

with JSSerializeOnce also sounds okay and rather better.

@hajifkd
Copy link
Owner Author

hajifkd commented Aug 24, 2017

Just note: cast to trait object was necessary.

Now, we should discuss the interface.
Unlike the current implementation, for instance,

impl JSSerialize for Box<Box<Fn(....) -> ...>> {
...
}

also sounds nice.

Considering the caller problem (#5), maybe the current one with some macro would be better, isn't 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

1 participant