eigr / spawn-rust-sdk

Apache License 2.0
5 stars 1 forks source link

Prost Protobuf issues #6

Open sleipnir opened 1 year ago

sleipnir commented 1 year ago

Blocked by issues in the prost library regarding the Any message parser:

error[E0277]: the trait bound `Reply: prost::name::Name` is not satisfied
  --> spawn-examples/src/joe.rs:16:27
   |
16 |                 .response(&Reply::default())
   |                  -------- ^^^^^^^^^^^^^^^^^ the trait `prost::name::Name` is not implemented for `Reply`
   |                  |
   |                  required by a bound introduced by this call
   |
   = help: the following other types implement trait `prost::name::Name`:
             prost_types::Any
             prost_types::Duration
             prost_types::Timestamp
note: required by a bound in `spawn_rs::value::Value::response`
  --> /home/sleipnir/workspaces/eigr/eigr-labs/spawn-rust-sdk/spawn-rs/src/value.rs:34:12

Related to https://github.com/tokio-rs/prost/issues/921 and https://github.com/tokio-rs/prost/pull/923

sleipnir commented 1 year ago

For now I created a workaround making the user enter the name of the fully qualified protobuf type:

pub fn set_language(msg: Message, ctx: Context) -> Value {
    info!("Actor msg: {:?}", msg);
    return match msg.body::<Request>() {
        Ok(request) => {
            let lang = request.language;
            info!("Setlanguage To: {:?}", lang);
            let mut reply = Reply::default();
            reply.response = lang;

            match &ctx.state::<State>() {
                Some(state) => Value::new()
                    .state::<State>(&state.as_ref().unwrap(), "domain.State".to_string()) // workaround here
                    .response(&reply, "domain.Reply".to_string())
                    .to_owned(),
                _ => Value::new()
                    .state::<State>(&State::default(), "domain.State".to_string()) // workaround here
                    .response(&reply, "domain.Reply".to_string())
                    .to_owned(),
            }
        }
        Err(_e) => Value::new()
            .state::<State>(&State::default(), "domain.State".to_string()) // workaround here
            .to_owned(),
    };
}