diff --git a/capnp-rpc/examples/hello-world/server.rs b/capnp-rpc/examples/hello-world/server.rs index b019a03fe..2eff13aa7 100644 --- a/capnp-rpc/examples/hello-world/server.rs +++ b/capnp-rpc/examples/hello-world/server.rs @@ -38,8 +38,7 @@ impl hello_world::Server for HelloWorldImpl { let request = pry!(pry!(params.get()).get_request()); let name = pry!(pry!(request.get_name()).to_str()); let message = format!("Hello, {name}!"); - - results.get().init_reply().set_message(&message[..]); + results.get().init_reply().set_message(message); Promise::ok(()) } diff --git a/capnp-rpc/examples/pubsub/server.rs b/capnp-rpc/examples/pubsub/server.rs index 4f743261f..f037c576a 100644 --- a/capnp-rpc/examples/pubsub/server.rs +++ b/capnp-rpc/examples/pubsub/server.rs @@ -166,9 +166,10 @@ pub async fn main() -> Result<(), Box> { if subscriber.requests_in_flight < 5 { subscriber.requests_in_flight += 1; let mut request = subscriber.client.push_message_request(); - request.get().set_message( - &format!("system time is: {:?}", ::std::time::SystemTime::now())[..], - )?; + request.get().set_message(format!( + "system time is: {:?}", + ::std::time::SystemTime::now() + ))?; let subscribers2 = subscribers1.clone(); tokio::task::spawn_local(request.send().promise.map( move |r| match r { diff --git a/capnp/src/text.rs b/capnp/src/text.rs index babeb4eb0..2229fe4bc 100644 --- a/capnp/src/text.rs +++ b/capnp/src/text.rs @@ -318,35 +318,16 @@ impl<'a> crate::traits::SetterInput for Reader<'a> { } } -// Text field setters are generated with a signature like -// ``` -// set_foo(&mut self, value: impl SetterInput) -// ``` -// Combined with the below impls of `SetterInput`, this -// allows text fields to be conveniently set from values -// of type `&str`. - -impl<'a> crate::traits::SetterInput for &'a str { +// Allow text fields to be set with &str or String or anything +// else that implements `AsRef`. +impl> crate::traits::SetterInput for T { #[inline] fn set_pointer_builder<'b>( mut pointer: crate::private::layout::PointerBuilder<'b>, - value: &'a str, + value: T, _canonicalize: bool, ) -> Result<()> { - pointer.set_text(value.into()); - Ok(()) - } -} - -#[cfg(feature = "alloc")] -impl<'a> crate::traits::SetterInput for &'a alloc::string::String { - #[inline] - fn set_pointer_builder<'b>( - mut pointer: crate::private::layout::PointerBuilder<'b>, - value: &'a alloc::string::String, - _canonicalize: bool, - ) -> Result<()> { - pointer.set_text(value.as_str().into()); + pointer.set_text(value.as_ref().into()); Ok(()) } }