Skip to content

Commit ce18a58

Browse files
committed
cargo fmt
1 parent c768f18 commit ce18a58

21 files changed

+545
-370
lines changed

examples/fread.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
use nuclei::*;
2-
use std::io;
3-
use std::time::Duration;
42
use std::fs::File;
3+
use std::io;
54
use std::path::PathBuf;
5+
use std::time::Duration;
66

77
use futures::AsyncRead;
88
use futures_util::io::AsyncReadExt;
99

10-
1110
fn main() -> io::Result<()> {
1211
let x = drive(async {
1312
let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
@@ -23,4 +22,4 @@ fn main() -> io::Result<()> {
2322
println!("{}", x);
2423

2524
Ok(())
26-
}
25+
}

examples/h1-server.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ use nuclei::*;
22
use std::net::TcpListener;
33

44
use anyhow::Result;
5-
use futures::prelude::*;
6-
use http_types::{Request, Response, StatusCode};
75
use async_dup::Arc;
86
use futures::pending;
7+
use futures::prelude::*;
8+
use http_types::{Request, Response, StatusCode};
99

1010
/// Serves a request and returns a response.
1111
async fn serve(req: Request) -> http_types::Result<Response> {
@@ -30,7 +30,7 @@ async fn listen(listener: Handle<TcpListener>) -> Result<()> {
3030
// Spawn a background task serving this connection.
3131
let stream = Arc::new(stream);
3232
spawn(async move {
33-
if let Err(err) = async_h1::accept( stream, serve).await {
33+
if let Err(err) = async_h1::accept(stream, serve).await {
3434
println!("Connection error: {:#?}", err);
3535
}
3636
});

examples/tcp-server.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
use futures::io;
12
use nuclei::*;
23
use std::net::{TcpListener, TcpStream};
3-
use futures::io;
44

55
async fn echo(stream: Handle<TcpStream>) -> io::Result<()> {
66
io::copy(&stream, &mut &stream).await?;
@@ -23,4 +23,4 @@ fn main() -> io::Result<()> {
2323
spawn_blocking(|| echo(stream));
2424
}
2525
})
26-
}
26+
}

src/lib.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
mod runtime;
1+
mod async_io;
22
mod handle;
3+
mod proactor;
4+
mod runtime;
35
mod submission_handler;
4-
mod async_io;
56
mod sys;
6-
mod waker;
7-
mod proactor;
87
mod utils;
8+
mod waker;
99

1010
#[cfg(not(any(
1111
target_os = "linux", // epoll, iouring
@@ -21,7 +21,6 @@ mod utils;
2121
)))]
2222
compile_error!("Target OS is not supported");
2323

24-
2524
#[cfg(any(
2625
target_os = "macos",
2726
target_os = "ios",
@@ -48,4 +47,4 @@ mod syscore {
4847
}
4948

5049
pub use proactor::*;
51-
pub use runtime::runtime::*;
50+
pub use runtime::runtime::*;

src/runtime.rs

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@ macro_rules! runtime_methods {
44
use std::future::Future;
55

66
pub fn spawn<F>(future: F) -> JoinHandle<F::Output>
7-
where
8-
F: Future + Send + 'static,
9-
F::Output: Send + 'static,
7+
where
8+
F: Future + Send + 'static,
9+
F::Output: Send + 'static,
1010
{
1111
RUNTIME.spawn(future)
1212
}
1313

1414
pub fn spawn_blocking<F, T>(task: F) -> JoinHandle<T>
15-
where
16-
F: FnOnce() -> T + Send + 'static,
17-
T: Send + 'static,
15+
where
16+
F: FnOnce() -> T + Send + 'static,
17+
T: Send + 'static,
1818
{
1919
RUNTIME.spawn_blocking(task)
2020
}
2121

2222
pub fn block_on<F>(future: F) -> F::Output
23-
where
24-
F: Future + Send + 'static,
25-
F::Output: Send + 'static,
23+
where
24+
F: Future + Send + 'static,
25+
F::Output: Send + 'static,
2626
{
2727
RUNTIME.block_on(future)
2828
}
@@ -31,54 +31,50 @@ macro_rules! runtime_methods {
3131

3232
#[cfg(feature = "bastion")]
3333
pub mod runtime {
34+
use agnostik::executors::BastionExecutor;
35+
use agnostik::{Agnostik, AgnostikExecutor};
3436
use once_cell::sync::Lazy;
35-
use agnostik::{AgnostikExecutor, Agnostik};
36-
use agnostik::executors::{BastionExecutor};
3737

38-
static RUNTIME: Lazy<BastionExecutor> = Lazy::new(|| unsafe {
39-
std::mem::transmute(Agnostik::bastion())
40-
});
38+
static RUNTIME: Lazy<BastionExecutor> =
39+
Lazy::new(|| unsafe { std::mem::transmute(Agnostik::bastion()) });
4140

4241
runtime_methods!();
4342
}
4443

4544
#[cfg(feature = "tokio")]
4645
pub mod runtime {
47-
use once_cell::sync::Lazy;
48-
use agnostik::{Agnostik, LocalAgnostikExecutor};
4946
use agnostik::executors::TokioExecutor;
47+
use agnostik::{Agnostik, LocalAgnostikExecutor};
48+
use once_cell::sync::Lazy;
5049

51-
static RUNTIME: Lazy<TokioExecutor> = Lazy::new(|| unsafe {
52-
std::mem::transmute(Agnostik::tokio())
53-
});
50+
static RUNTIME: Lazy<TokioExecutor> =
51+
Lazy::new(|| unsafe { std::mem::transmute(Agnostik::tokio()) });
5452

5553
runtime_methods!();
5654
}
5755

5856
#[cfg(feature = "asyncstd")]
5957
pub mod runtime {
60-
use once_cell::sync::Lazy;
61-
use agnostik::{Agnostik, LocalAgnostikExecutor};
6258
use agnostik::executors::AsyncStdExecutor;
59+
use agnostik::{Agnostik, LocalAgnostikExecutor};
60+
use once_cell::sync::Lazy;
6361

64-
static RUNTIME: Lazy<AsyncStdExecutor> = Lazy::new(|| unsafe {
65-
std::mem::transmute(Agnostik::async_std())
66-
});
62+
static RUNTIME: Lazy<AsyncStdExecutor> =
63+
Lazy::new(|| unsafe { std::mem::transmute(Agnostik::async_std()) });
6764

6865
runtime_methods!();
6966
}
7067

7168
#[cfg(feature = "smol")]
7269
pub mod runtime {
73-
use once_cell::sync::Lazy;
74-
use agnostik::{Agnostik, LocalAgnostikExecutor};
7570
use agnostik::executors::SmolExecutor;
71+
use agnostik::{Agnostik, LocalAgnostikExecutor};
72+
use once_cell::sync::Lazy;
7673

77-
static RUNTIME: Lazy<SmolExecutor> = Lazy::new(|| unsafe {
78-
std::mem::transmute(Agnostik::smol())
79-
});
74+
static RUNTIME: Lazy<SmolExecutor> =
75+
Lazy::new(|| unsafe { std::mem::transmute(Agnostik::smol()) });
8076

8177
runtime_methods!();
8278
}
8379

84-
pub use runtime::*;
80+
pub use runtime::*;

src/submission_handler.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
1-
use futures::io::{
2-
AsyncRead, AsyncWrite, AsyncBufRead, AsyncSeek
3-
};
4-
use std::marker::PhantomData as marker;
5-
use std::{task::{Context, Poll}, io, pin::Pin, future::Future, ops::{DerefMut, Deref}};
61
use super::handle::{Handle, HandleOpRegisterer};
7-
2+
use futures::io::{AsyncBufRead, AsyncRead, AsyncSeek, AsyncWrite};
3+
use std::marker::PhantomData as marker;
4+
use std::{
5+
future::Future,
6+
io,
7+
ops::{Deref, DerefMut},
8+
pin::Pin,
9+
task::{Context, Poll},
10+
};
811

912
pub struct SubmissionHandler<T>(marker<T>)
1013
where
11-
T: Unpin;
14+
T: Unpin;
1215

1316
impl<T> SubmissionHandler<T>
1417
where
15-
T: Unpin + HandleOpRegisterer
18+
T: Unpin + HandleOpRegisterer,
1619
{
1720
pub fn handle_read(
1821
handle: Pin<&mut T>,
1922
cx: &mut Context,
20-
completion_dispatcher: impl Future<Output=io::Result<usize>> + 'static
23+
completion_dispatcher: impl Future<Output = io::Result<usize>> + 'static,
2124
) -> Poll<io::Result<usize>> {
2225
let handle = handle.get_mut();
2326
let read_result = handle.read_registerer();
@@ -46,7 +49,7 @@ where
4649
pub fn handle_write(
4750
handle: Pin<&mut T>,
4851
cx: &mut Context,
49-
completion_dispatcher: impl Future<Output=io::Result<usize>> + 'static
52+
completion_dispatcher: impl Future<Output = io::Result<usize>> + 'static,
5053
) -> Poll<io::Result<usize>> {
5154
let handle = handle.get_mut();
5255
let write_result = handle.write_registerer();
@@ -71,4 +74,4 @@ where
7174

7275
poll
7376
}
74-
}
77+
}

0 commit comments

Comments
 (0)