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

Deriving Serialize for a struct from external crate which uses generics #2483

Closed
attacker0211 opened this issue Jun 23, 2023 · 1 comment
Closed
Labels

Comments

@attacker0211
Copy link

attacker0211 commented Jun 23, 2023

use num_complex::{Complex64}
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize)]
#[serde(remote = "Complex64")]
pub struct Complex64Def {
    pub re: f64,
    pub im: f64,
}

impl From<Complex64Def> for Complex64 {
    fn from(def: Complex64Def) -> Complex64 {
        Complex64::new(def.re, def.im)
    }
}

fn main() {
    let mut one = Complex64 { re: 1.0, im: 2.0 };
    let mut json_buffer = serde_json::to_string(&one).unwrap();
    println!("{}", json_buffer);
}

I'm trying to convert some types to json. This is the simplified version of what doesn't work. The above throws out the error the trait `Serialize` is not implemented for Complex<f64>. Related to #2327.
Use num_complex::Complex with or without generic typing T doesn't work either (num_complex::Complex<f64> = num_complex::Complex64).

@dtolnay
Copy link
Member

dtolnay commented Jul 9, 2023

Hi @attacker0211, sorry that no one was able to provide guidance here. If this is still an issue, you could try taking this question to any of the resources shown in https://www.rust-lang.org/community. This library is one of the most widely used Rust libraries and plenty of people will be able to provide guidance about it.

@dtolnay dtolnay closed this as completed Jul 9, 2023
@dtolnay dtolnay added the support label Jul 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants