riker icon indicating copy to clipboard operation
riker copied to clipboard

Implement From<> trait for actor message enum

Open elenaf9 opened this issue 4 years ago • 0 comments

The actor macro currently implements Into<#name> for #ty for each message type (#ty) in the message enum (#name), which enables converting from a specific message to the expected message enum. From my point of view, implementing From<#ty> for #name would also implement the Into trait, but additionally serve more use cases, especially when working with generic message types, e.g. in such a case:

struct MyMessage;

struct MyStruct<T>
where
     T: From<MyMessage>
{
    actor: ActorRef<T>
}

impl<T> MyStruct<T> 
where
     T: From<MyMessage>
{
     fn msg_actor(&self, msg: MyMessage) {
           self.actor.tell(msg, None)
    }
}

Was there a specific reason for implementing Into instead of From?

elenaf9 avatar Feb 01 '21 11:02 elenaf9