I have two identical structs in two different modules:
Module data
has struct data::Branch:
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Branch {
pub id: Uuid,
pub name: String,
pub parents: Vec<Branch>,
pub children: Vec<Branch>,
}
And module graphql
has struct graphql::Branch:
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Branch {
pub id: Uuid,
pub name: String,
pub parents: Vec<Branch>,
pub children: Vec<Branch>,
}
I can not figure it out how to implement impl From<Vec<data::Branch>> for Vec<Branch>
in graphql
module?
impl From<data::branch::Branch> for Branch {
fn from(branch: data::branch::Branch) -> Branch {
Branch {
id: branch.id,
name: branch.name,
content: branch.name,
parents: branch.parents.into(),
children: branch.children.into(),
created_at: branch.created_at,
updated_at: branch.updated_at,
}
}
}
impl From<Vec<data::branch::Branch>> for Vec<Branch> {
fn from(_: Vec<data::branch::Branch>) -> Self {
todo!();
}
}
I have faced this error and don't know how to handle it.
error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate
--> src/graphql/branch/branch.rs:64:1
|
64 | impl From<Vec<data::branch::Branch>> for Vec<Branch> {
| ^^^^^-------------------------------^^^^^-----------
| | | |
| | | `Vec` is not defined in the current crate
| | `Vec` is not defined in the current crate
| impl doesn't use only types from inside the current crate
|
= note: define and implement a trait or new type instead