websockets-rs / rust-websocket

A WebSocket (RFC6455) library written in Rust
http://websockets-rs.github.io/rust-websocket/
MIT License
1.55k stars 223 forks source link

Implement From<String> for OwnedMessage #203

Closed jean-airoldie closed 5 years ago

jean-airoldie commented 5 years ago

Hi, Is there any reason why OwnedMessage does not implement From<String>? Since it is used as a SinkItem of the async client, I can't use the Sink produced by the async client in the following fashion:

pub fn foo<S: Sink>(sink: &mut S)
where
    <S as Sink>::SinkItem: From<String>,
    <S as Sink>::SinkError: Debug,
{
    let text = "ok".to_string();
    sink.start_send(text.into()).unwrap();
}

In the current configuration, I am forced to define my own intermediary type which implements From<String> and Into<OwnedMessage>.

Thanks!

vi commented 5 years ago

Is there any reason why OwnedMessage does not implement From?

Probably no. Pull request is welcome.

FreeFull commented 5 years ago

In that case, should it also implement From<Vec<u8>>?

vi commented 5 years ago

Yes.