Skip to content

Commit

Permalink
drop static lifetime requirement for request name
Browse files Browse the repository at this point in the history
  • Loading branch information
stevefan1999-personal committed Oct 9, 2024
1 parent 33b0b21 commit 240f94f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
2 changes: 1 addition & 1 deletion plugins/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ impl<'a> ServiceGenerator<'a> {
),*
}
impl ::tarpc::RequestName for #request_ident {
fn name(&self) -> &'static str {
fn name(&self) -> &str {
match self {
#(
#( #method_cfgs )*
Expand Down
23 changes: 10 additions & 13 deletions tarpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ use std::{any::Any, error::Error, io, sync::Arc, time::Instant};
/// A message from a client to a server.
#[derive(Debug)]
#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
#[non_exhaustive]
pub enum ClientMessage<T> {
/// A request initiated by a user. The server responds to a request by invoking a
/// service-provided request handler. The handler completes with a [`response`](Response), which
Expand All @@ -280,7 +279,6 @@ pub enum ClientMessage<T> {

/// A request from a client to a server.
#[derive(Clone, Copy, Debug)]
#[non_exhaustive]
#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
pub struct Request<T> {
/// Trace context, deadline, and other cross-cutting concerns.
Expand All @@ -294,14 +292,14 @@ pub struct Request<T> {
/// Implemented by the request types generated by tarpc::service.
pub trait RequestName {
/// The name of a request.
fn name(&self) -> &'static str;
fn name(&self) -> &str;
}

impl<Req> RequestName for Arc<Req>
where
Req: RequestName,
{
fn name(&self) -> &'static str {
fn name(&self) -> &str {
self.as_ref().name()
}
}
Expand All @@ -310,57 +308,56 @@ impl<Req> RequestName for Box<Req>
where
Req: RequestName,
{
fn name(&self) -> &'static str {
fn name(&self) -> &str {
self.as_ref().name()
}
}

/// Impls for common std types for testing.
impl RequestName for String {
fn name(&self) -> &'static str {
fn name(&self) -> &str {
"string"
}
}

impl RequestName for char {
fn name(&self) -> &'static str {
fn name(&self) -> &str {
"char"
}
}

impl RequestName for () {
fn name(&self) -> &'static str {
fn name(&self) -> &str {
"unit"
}
}

impl RequestName for i32 {
fn name(&self) -> &'static str {
fn name(&self) -> &str {
"i32"
}
}

impl RequestName for u32 {
fn name(&self) -> &'static str {
fn name(&self) -> &str {
"u32"
}
}

impl RequestName for i64 {
fn name(&self) -> &'static str {
fn name(&self) -> &str {
"i64"
}
}

impl RequestName for u64 {
fn name(&self) -> &'static str {
fn name(&self) -> &str {
"u64"
}
}

/// A response from a server to a client.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[non_exhaustive]
#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
pub struct Response<T> {
/// The ID of the request being responded to.
Expand Down

0 comments on commit 240f94f

Please sign in to comment.