-
-
Notifications
You must be signed in to change notification settings - Fork 777
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
how to reexport Serialize, Deserialize? #1465
Comments
There is no supported way to do this currently. The downstream crate will need to add its own dependency on serde. If it is an absolute requirement that this work, then you could fork serde_derive and modify it to emit paths that refer to common::serde everywhere instead of serde. |
I am confusing why it is impossible. could you please give me some explain or I am lose some extra information? |
The code emitted by serde_derive would look something like: impl serde::Serialize for Test {... But if there is no such thing as |
so we need some way to make serde been visible in the main crate. is that exactly what |
All that's needed is for the main crate to add a dependency on Serde. [dependencies]
serde = "1.0" From there, the derived code will find it. |
i know. yes, of course, i could do that, but i think it should not do. i am confusing why we have no ability to do. it seems rust could not use other crate's depended crate, right? |
I have a very large repo/workspace at work. Many crates have to have their own serde line in the Cargo.toml now and it's going to potentially be a bit of a chore someday in the future. We already have a utils crate that re-exports common cli and logging setup. We have another for grouping common dependencies for certain tasks. |
this is painful for us, we have several repos with a few dozen crates and every time we want to do something with the serde dependencies it is a tedious hunt to go find all the places it is being used |
@woodgear why did you close this, it seems unresolved? |
Sorry to bother, is there any update on this? My usecase is the same as OP |
I have the same issue as the last few posters. |
Based on yewstack/yew#1454 looks like this is fixable now with |
So how is this fixable? I'm trying to get it to work, but not having luck |
Has anybody found a way around this? |
For anyone looking, I've found a way around this using a derive helper attribute that serde implements (here; couldn't find where it's documented). Usage: use common::serde::{self, Deserialize, Serialize}
#[derive(Copy, Clone, Debug, Deserialize, Serialize)]
#[serde(crate = "self::serde")] // must be below the derive attribute
struct Vertex {
position: [u32; 3],
} |
The above worked for me! Thank you! |
just like this question
#856 (comment)
the common crate
the main crate who want to use serde from common ccrate
it should be work but always report error like
how should i do that?
The text was updated successfully, but these errors were encountered: