Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expose some structs to be able to use a non-tokio executor #296

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion tarpc/src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub mod client;
pub mod context;
pub mod server;
pub mod transport;
pub(crate) mod util;
pub mod util;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What did you need util for? This module isn't intended to be publicly exposed.


pub use crate::{client::Client, server::Server, trace, transport::sealed::Transport};

Expand Down Expand Up @@ -86,6 +86,16 @@ pub struct Response<T> {
pub message: Result<T, ServerError>,
}

impl<T> Response<T> {
/// Construct a new response
pub fn new(request_id: u64, message: Result<T, ServerError>) -> Self {
Self {
request_id,
message,
}
}
}

/// An error response from a server to a client.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[non_exhaustive]
Expand All @@ -105,6 +115,13 @@ pub struct ServerError {
pub detail: Option<String>,
}

impl ServerError {
/// Construct a new server error
pub fn new(kind: io::ErrorKind, detail: Option<String>) -> Self {
Self { kind, detail }
}
}

impl From<ServerError> for io::Error {
fn from(e: ServerError) -> io::Error {
io::Error::new(e.kind, e.detail.unwrap_or_default())
Expand Down
4 changes: 3 additions & 1 deletion tarpc/src/rpc/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.

//! Provides a utility functions for serde, time and hashmap.

use std::{
collections::HashMap,
hash::{BuildHasher, Hash},
time::{Duration, SystemTime},
};

#[cfg(feature = "serde")]
pub mod serde;
pub(crate) mod serde;

/// Extension trait for [SystemTimes](SystemTime) in the future, i.e. deadlines.
pub trait TimeUntil {
Expand Down