Replies: 2 comments 1 reply
-
This is a general (intentional) limitation of Rust's trait system: To implement a trait for a type in a crate, you have to either implement the trait or the type in the same crate. In this case, you have a type from a foreign crate The "common" approach to this for "non-generated" trait implementations is to wrap the type in a new-type (a tuple That won't help you here, as the derive macros that provide the implementations for The best I can think of right now is to implement |
Beta Was this translation helpful? Give feedback.
-
@filmor Thank you for the thorough explanation! I know the discussion may be stale, but I was wondering if you could provide a simple example of how this manual implementation of Encoder and Decoder would be done. // external struct
pub struct TestStruct {
pub year: usize,
pub month: usize,
}
struct Wrapper(TestStruct);
impl Encoder for DateTime {
fn encode<'b>(&self, env: Env<'b>) -> Term<'b> {
// I doubt this is correct
match elixir_struct::make_ex_struct(env, "ICalendar.DateTime") {
Ok(term) => term,
Err(err) => panic!("{:#?}", err),
}
}
}
impl<'a> Decoder<'a> for DateTime {
fn decode(term: Term<'a>) -> NifResult<Self> {
// unsure
}
} |
Beta Was this translation helpful? Give feedback.
-
Is there a way to import structs from another library in rust to elixir without having to rewrite the entire struct again? Been looking through the docs and cant find much on this.
Beta Was this translation helpful? Give feedback.
All reactions