Skip to content

Commit

Permalink
chore: Consistently format imports... (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
rklaehn authored Nov 14, 2024
2 parents 4d23e36 + 33fb08b commit 08750c5
Show file tree
Hide file tree
Showing 28 changed files with 163 additions and 151 deletions.
3 changes: 2 additions & 1 deletion examples/errors.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use std::result;

use derive_more::{Display, From, TryInto};
use quic_rpc::{message::RpcMsg, RpcClient, RpcServer, Service};
use serde::{Deserialize, Serialize};
use std::result;

#[derive(Debug, Serialize, Deserialize)]
struct WriteRequest(String, Vec<u8>);
Expand Down
7 changes: 3 additions & 4 deletions examples/macro.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
mod store_rpc {
use std::fmt::Debug;

use quic_rpc::rpc_service;
use serde::{Deserialize, Serialize};
use std::fmt::Debug;

pub type Cid = [u8; 32];

Expand Down Expand Up @@ -51,9 +52,7 @@ mod store_rpc {
use async_stream::stream;
use futures_lite::{Stream, StreamExt};
use futures_util::SinkExt;
use quic_rpc::client::RpcClient;
use quic_rpc::server::run_server_loop;
use quic_rpc::transport::flume;
use quic_rpc::{client::RpcClient, server::run_server_loop, transport::flume};
use store_rpc::*;

#[derive(Clone)]
Expand Down
20 changes: 11 additions & 9 deletions examples/modularize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
//! unchanged.
use anyhow::Result;
use app::AppService;
use futures_lite::StreamExt;
use futures_util::SinkExt;
use quic_rpc::{client::BoxedConnector, transport::flume, Listener, RpcClient, RpcServer};
use tracing::warn;

use app::AppService;

#[tokio::main]
async fn main() -> Result<()> {
// Spawn an inmemory connection.
Expand Down Expand Up @@ -99,12 +98,13 @@ mod app {
//!
//! It could also easily compose services from other crates or internal modules.
use super::iroh;
use anyhow::Result;
use derive_more::{From, TryInto};
use quic_rpc::{message::RpcMsg, server::RpcChannel, Listener, RpcClient, Service};
use serde::{Deserialize, Serialize};

use super::iroh;

#[derive(Debug, Serialize, Deserialize, From, TryInto)]
pub enum Request {
Iroh(iroh::Request),
Expand Down Expand Up @@ -271,6 +271,8 @@ mod calc {
//! This is a library providing a service, and a client. E.g. iroh-bytes or iroh-hypermerge.
//! It does not use any `super` imports, it is completely decoupled.
use std::fmt::Debug;

use anyhow::{bail, Result};
use derive_more::{From, TryInto};
use futures_lite::{Stream, StreamExt};
Expand All @@ -280,7 +282,6 @@ mod calc {
RpcClient, Service,
};
use serde::{Deserialize, Serialize};
use std::fmt::Debug;

#[derive(Debug, Serialize, Deserialize)]
pub struct AddRequest(pub i64, pub i64);
Expand Down Expand Up @@ -385,6 +386,12 @@ mod clock {
//! This is a library providing a service, and a client. E.g. iroh-bytes or iroh-hypermerge.
//! It does not use any `super` imports, it is completely decoupled.
use std::{
fmt::Debug,
sync::{Arc, RwLock},
time::Duration,
};

use anyhow::Result;
use derive_more::{From, TryInto};
use futures_lite::{stream::Boxed as BoxStream, Stream, StreamExt};
Expand All @@ -395,11 +402,6 @@ mod clock {
RpcClient, Service,
};
use serde::{Deserialize, Serialize};
use std::{
fmt::Debug,
sync::{Arc, RwLock},
time::Duration,
};
use tokio::sync::Notify;

#[derive(Debug, Serialize, Deserialize)]
Expand Down
12 changes: 4 additions & 8 deletions examples/split/client/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
#![allow(unknown_lints, non_local_definitions)]

use std::net::SocketAddr;
use std::sync::Arc;
use std::{net::SocketAddr, sync::Arc};

use anyhow::Result;
use futures::sink::SinkExt;
use futures::stream::StreamExt;
use quic_rpc::transport::quinn::QuinnConnector;
use quic_rpc::RpcClient;
use quinn::crypto::rustls::QuicClientConfig;
use quinn::{ClientConfig, Endpoint};
use futures::{sink::SinkExt, stream::StreamExt};
use quic_rpc::{transport::quinn::QuinnConnector, RpcClient};
use quinn::{crypto::rustls::QuicClientConfig, ClientConfig, Endpoint};
use types::compute::*;

// types::create_compute_client!(ComputeClient);
Expand Down
8 changes: 3 additions & 5 deletions examples/split/server/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use std::{net::SocketAddr, sync::Arc};

use async_stream::stream;
use futures::stream::{Stream, StreamExt};
use quic_rpc::server::run_server_loop;
use quic_rpc::transport::quinn::QuinnListener;
use quic_rpc::{server::run_server_loop, transport::quinn::QuinnListener};
use quinn::{Endpoint, ServerConfig};
use std::net::SocketAddr;
use std::sync::Arc;

use types::compute::*;

#[derive(Clone)]
Expand Down
3 changes: 2 additions & 1 deletion examples/split/types/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
pub mod compute {
use std::fmt::Debug;

use quic_rpc::rpc_service;
use serde::{Deserialize, Serialize};
use std::fmt::Debug;

/// compute the square of a number
#[derive(Debug, Serialize, Deserialize)]
Expand Down
3 changes: 2 additions & 1 deletion examples/store.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#![allow(clippy::enum_variant_names)]
use std::{fmt::Debug, result};

use async_stream::stream;
use derive_more::{From, TryInto};
use futures_lite::{Stream, StreamExt};
Expand All @@ -9,7 +11,6 @@ use quic_rpc::{
*,
};
use serde::{Deserialize, Serialize};
use std::{fmt::Debug, result};

type Cid = [u8; 32];
#[derive(Debug, Serialize, Deserialize)]
Expand Down
3 changes: 2 additions & 1 deletion quic-rpc-derive/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use std::collections::{BTreeMap, HashSet};

use proc_macro::TokenStream;
use proc_macro2::{Span, TokenStream as TokenStream2};
use quote::{quote, ToTokens};
use std::collections::{BTreeMap, HashSet};
use syn::{
parse::{Parse, ParseStream},
parse_macro_input,
Expand Down
17 changes: 9 additions & 8 deletions src/client.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
//! Client side api
//!
//! The main entry point is [RpcClient].
use crate::{
transport::{boxed::BoxableConnector, mapped::MappedConnector, StreamTypes},
Connector, Service,
};
use futures_lite::Stream;
use futures_sink::Sink;

use pin_project::pin_project;
use std::{
fmt::Debug,
marker::PhantomData,
pin::Pin,
task::{Context, Poll},
};

use futures_lite::Stream;
use futures_sink::Sink;
use pin_project::pin_project;

use crate::{
transport::{boxed::BoxableConnector, mapped::MappedConnector, StreamTypes},
Connector, Service,
};

/// Type alias for a boxed connection to a specific service
///
/// This is a convenience type alias for a boxed connection to a specific service.
Expand Down
39 changes: 20 additions & 19 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
//! # Example
//! ```
//! # async fn example() -> anyhow::Result<()> {
//! use quic_rpc::{message::RpcMsg, Service, RpcClient, RpcServer};
//! use serde::{Serialize, Deserialize};
//! use derive_more::{From, TryInto};
//! use quic_rpc::{message::RpcMsg, RpcClient, RpcServer, Service};
//! use serde::{Deserialize, Serialize};
//!
//! // Define your messages
//! #[derive(Debug, Serialize, Deserialize)]
Expand All @@ -39,21 +39,21 @@
//! }
//!
//! impl Service for PingService {
//! type Req = PingRequest;
//! type Res = PingResponse;
//! type Req = PingRequest;
//! type Res = PingResponse;
//! }
//!
//! // Define interaction patterns for each request type
//! impl RpcMsg<PingService> for Ping {
//! type Response = Pong;
//! type Response = Pong;
//! }
//!
//! // create a transport channel, here a memory channel for testing
//! let (server, client) = quic_rpc::transport::flume::channel(1);
//!
//! // client side
//! // create the rpc client given the channel and the service type
//! let mut client = RpcClient::<PingService,_>::new(client);
//! let mut client = RpcClient::<PingService, _>::new(client);
//!
//! // call the service
//! let res = client.rpc(Ping).await?;
Expand All @@ -64,12 +64,12 @@
//!
//! let handler = Handler;
//! loop {
//! // accept connections
//! let (msg, chan) = server.accept().await?.read_first().await?;
//! // dispatch the message to the appropriate handler
//! match msg {
//! PingRequest::Ping(ping) => chan.rpc(ping, handler, Handler::ping).await?,
//! }
//! // accept connections
//! let (msg, chan) = server.accept().await?.read_first().await?;
//! // dispatch the message to the appropriate handler
//! match msg {
//! PingRequest::Ping(ping) => chan.rpc(ping, handler, Handler::ping).await?,
//! }
//! }
//!
//! // the handler. For a more complex example, this would contain any state
Expand All @@ -78,21 +78,22 @@
//! struct Handler;
//!
//! impl Handler {
//! // the handle fn for a Ping request.
//! // the handle fn for a Ping request.
//!
//! // The return type is the response type for the service.
//! // Note that this must take self by value, not by reference.
//! async fn ping(self, _req: Ping) -> Pong {
//! Pong
//! }
//! // The return type is the response type for the service.
//! // Note that this must take self by value, not by reference.
//! async fn ping(self, _req: Ping) -> Pong {
//! Pong
//! }
//! }
//! # Ok(())
//! # }
//! ```
#![deny(missing_docs)]
#![deny(rustdoc::broken_intra_doc_links)]
use serde::{de::DeserializeOwned, Serialize};
use std::fmt::{Debug, Display};

use serde::{de::DeserializeOwned, Serialize};
pub mod client;
pub mod message;
pub mod server;
Expand Down
1 change: 0 additions & 1 deletion src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@
/// server_handle.await??;
/// Ok(())
/// }
///
/// ```
///
/// The generation of the macros in `CreateDispatch` and `CreateClient`
Expand Down
12 changes: 7 additions & 5 deletions src/message.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
//! Service definition
//!
//! Traits to define the behaviour of messages for services
use crate::Service;
use std::fmt::Debug;

pub use crate::pattern::bidi_streaming::{BidiStreaming, BidiStreamingMsg};
pub use crate::pattern::client_streaming::{ClientStreaming, ClientStreamingMsg};
pub use crate::pattern::rpc::{Rpc, RpcMsg};
pub use crate::pattern::server_streaming::{ServerStreaming, ServerStreamingMsg};
pub use crate::pattern::{
bidi_streaming::{BidiStreaming, BidiStreamingMsg},
client_streaming::{ClientStreaming, ClientStreamingMsg},
rpc::{Rpc, RpcMsg},
server_streaming::{ServerStreaming, ServerStreamingMsg},
};
use crate::Service;

/// Declares the interaction pattern for a message and a service.
///
Expand Down
12 changes: 6 additions & 6 deletions src/pattern/bidi_streaming.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
//! Bidirectional stream interaction pattern.
use std::{
error,
fmt::{self, Debug},
result,
};

use futures_lite::{Stream, StreamExt};
use futures_util::{FutureExt, SinkExt};

Expand All @@ -11,12 +17,6 @@ use crate::{
RpcClient, Service,
};

use std::{
error,
fmt::{self, Debug},
result,
};

/// Bidirectional streaming interaction pattern
///
/// After the initial request, the client can send updates and the server can
Expand Down
12 changes: 6 additions & 6 deletions src/pattern/client_streaming.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
//! Client streaming interaction pattern.
use std::{
error,
fmt::{self, Debug},
result,
};

use futures_lite::{future::Boxed, Future, StreamExt};
use futures_util::{FutureExt, SinkExt, TryFutureExt};

Expand All @@ -11,12 +17,6 @@ use crate::{
Connector, RpcClient, Service,
};

use std::{
error,
fmt::{self, Debug},
result,
};

/// Client streaming interaction pattern
///
/// After the initial request, the client can send updates, but there is only
Expand Down
12 changes: 6 additions & 6 deletions src/pattern/rpc.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
//! RPC interaction pattern.
use std::{
error,
fmt::{self, Debug},
result,
};

use futures_lite::{Future, StreamExt};
use futures_util::{FutureExt, SinkExt};

Expand All @@ -10,12 +16,6 @@ use crate::{
Connector, RpcClient, Service,
};

use std::{
error,
fmt::{self, Debug},
result,
};

/// Rpc interaction pattern
///
/// There is only one request and one response.
Expand Down
Loading

0 comments on commit 08750c5

Please sign in to comment.