serde_closure icon indicating copy to clipboard operation
serde_closure copied to clipboard

Closures are empty when serialized - am I doing something wrong?

Open King-Coyote opened this issue 2 years ago • 1 comments

Hey mate,

I think I might be doing something wrong. Suppose I have the following minimal example:

use serde_closure::*;

fn main() {
    let closure = Fn!(|x: i32| x + 1);
    println!("closure is {:?}", closure);

    let closure_str = serde_json::to_string(&closure).unwrap();
    println!("Serialised closure is {}", closure_str);
}

the output I get is:

closure is Fn<serde_test::main::{{closure}} at src/main.rs:4:19> { source: "| x : i32 | x + 1" }
Serialised closure is {}

Is this wrong or am I missing something? Here is my Cargo.toml:

[package]
name = "serde_test"
version = "0.1.0"
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
ron = "~0.6"
serde = "1.0"
serde_closure = "0.3.2"
serde_json = "~1.0"
serde_traitobject = "0.2.3"

King-Coyote avatar Jul 20 '21 00:07 King-Coyote

Rustc version is 1.54.0 nightly

King-Coyote avatar Jul 20 '21 00:07 King-Coyote