Remix.run Logo
▲ bombela 33 minutes ago

  pub trait Payloads {
      type Read;
      type Write;
  }

  pub enum FileOp<P: Payloads> {
      Read(P::Read),
      Write(P::Write),
  }

  pub struct Inputs;

  impl Payloads for Inputs {
      type Read = ();
      type Write = u8;
  }

  pub type Request = FileOp<Inputs>;

  pub struct Outputs;

  impl Payloads for Outputs {
      type Read = u8;
      type Write = ();
  }

  pub type Reply = FileOp<Outputs>;

  pub fn execute(request: Request) -> Reply {
      match request {
          Request::Read(()) => Reply::Read(42),
          Request::Write(_) => Reply::Write(()),
      }
  }
▲Jtsummers 21 minutes ago | parent [-]

This looks like it would handle synchronizing multiple variant records/enums, and if you just wanted the "plain" enum without any payload, you'd need to do:

  pub struct Bare;
  impl Payloads for Bare {
    type Read = ();
    type Write = ();
  }

  pub type BareFileOp = FileOp<Bare>
Correct? So you'd need to create it with BareFileOp::Read(()), but at least it wouldn't carry any overhead of actually containing data.