I cloned serde.
In the other crate, I specified the path to the local serde
:
serde = {path = "../../serde/serde", features = ["derive"]}
Also specified:
serde_json = "^1.0.127"
In the code:
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug)]
struct Tmp {
a: i64,
b: i32,
}
fn main() {
let tmp = Tmp { a: 2, b: 3 };
println!("Hello, world! {tmp:?}", );
serde_json::to_string(&tmp);
}
An error occurs:
cargo build
Compiling tmp v0.1.0 (C:\Users\letif\VS Code Projects\rust\mertex\tmp)
error[E0277]: the trait bound `Tmp: serde::ser::Serialize` is not satisfied
--> tmp\src/main.rs:12:27
|
12 | serde_json::to_string(&tmp);
| --------------------- ^^^^ the trait `serde::ser::Serialize` is not implemented for `Tmp`
| |
| required by a bound introduced by this call
|
= note: for local types consider adding `#[derive(serde::Serialize)]` to your `Tmp` type
= note: for types from other crates check whether the crate offers a `serde` feature flag
= help: the following other types implement trait `serde::ser::Serialize`:
&'a T
&'a mut T
()
(T,)
(T0, T1)
(T0, T1, T2)
(T0, T1, T2, T3)
(T0, T1, T2, T3, T4)
and 131 others
note: required by a bound in `serde_json::to_string`
--> C:\Users\letif\.cargo\registry\src\index.crates.io-6f17d22bba15001f\serde_json-1.0.127\src\ser.rs:2209:17
|
2207 | pub fn to_string<T>(value: &T) -> Result<String>
| --------- required by a bound in this function
2208 | where
2209 | T: ?Sized + Serialize,
| ^^^^^^^^^ required by this bound in `to_string`
For more information about this error, try `rustc --explain E0277`.
error: could not compile `tmp` (bin "tmp") due to 1 previous error
The same thing happens with:
serde = {git = “https://github.com/serde-rs/serde.git”, features = [“derive”]}
.
While with serde = {version = “1.0.209”, features = [“derive”]}
the code compiles.