Traits are basically what you want here. You can have a trait with the emit
method and implement it on both structs.
On 25 Dec 2012 19:25, "Michael Neumann" <[email protected]> wrote:
> Hi,
>
> I am trying to switch over my msgpack implementation [1] to use the
> Encoder/Decoder trait from serialize.rs. I want to implement a basic
> encoder and a more optimized one (in terms of generated storage).
> Most of the emit_() functions will be shared between the two, just
> integers would be emitted based on their actual range and not depending
> on their type. Now my question is wheather I can reuse some code by
> using something like a Mixin?
>
> Is there something like this:
>
> struct Encoder { ... }
>
> pub impl Encoder : serialize::Encoder {
> fn emit_nil ...
> ...
> }
>
> struct OptEncoder { ... }
>
> pub impl OptEncoder : serialize::Encoder {
> include Encoder
>
> fn emit_uint(...) { ... } // overwrite emit_uint
> }
>
> Or how would you implement that?
>
> Actually what I want is some way to literally "include" some functions into
> the scope of an implementation (like a mixin). Similar in the way Ruby or
> Sather handles this.
>
> Merry Christmas!
>
> Michael
> ______________________________**_________________
> Rust-dev mailing list
> [email protected]
> https://mail.mozilla.org/**listinfo/rust-dev<https://mail.mozilla.org/listinfo/rust-dev>
>
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev