Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
o0Ignition0o committed Jul 19, 2020
1 parent 35bc77a commit 1b28531
Show file tree
Hide file tree
Showing 22 changed files with 554 additions and 381 deletions.
8 changes: 4 additions & 4 deletions examples/fread.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use nuclei::*;
use std::io;
use std::time::Duration;
use std::fs::{File, OpenOptions};
use std::io;
use std::path::PathBuf;
use std::time::Duration;
use std::time::Duration;

use futures::AsyncRead;
use futures_util::io::AsyncReadExt;


fn main() -> io::Result<()> {
let x = drive(async {
let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
Expand All @@ -25,4 +25,4 @@ fn main() -> io::Result<()> {
println!("Length of file is {}", x.len());

Ok(())
}
}
6 changes: 3 additions & 3 deletions examples/h1-server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use nuclei::*;
use std::net::TcpListener;

use anyhow::Result;
use futures::prelude::*;
use http_types::{Request, Response, StatusCode};
use async_dup::Arc;
use futures::pending;
use futures::prelude::*;
use http_types::{Request, Response, StatusCode};

/// Serves a request and returns a response.
async fn serve(req: Request) -> http_types::Result<Response> {
Expand All @@ -30,7 +30,7 @@ async fn listen(listener: Handle<TcpListener>) -> Result<()> {
// Spawn a background task serving this connection.
let stream = Arc::new(stream);
spawn(async move {
if let Err(err) = async_h1::accept( stream, serve).await {
if let Err(err) = async_h1::accept(stream, serve).await {
println!("Connection error: {:#?}", err);
}
});
Expand Down
4 changes: 2 additions & 2 deletions examples/tcp-server.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use futures::io;
use nuclei::*;
use std::net::{TcpListener, TcpStream};
use futures::io;

async fn echo(stream: Handle<TcpStream>) -> io::Result<()> {
io::copy(&stream, &mut &stream).await?;
Expand All @@ -23,4 +23,4 @@ fn main() -> io::Result<()> {
spawn_blocking(|| echo(stream));
}
})
}
}
1 change: 1 addition & 0 deletions src/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub struct Handle<T> {
#[cfg(unix)]
pub(crate) chan: Option<CompletionChan>,
/// File operation storage
#[cfg(unix)]
pub(crate) store_file: Option<StoreFile>,
/// Completion callback for read
pub(crate) read: Arc<TTas<Option<AsyncOp<usize>>>>,
Expand Down
11 changes: 5 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
mod runtime;
mod async_io;
mod handle;
mod proactor;
mod runtime;
mod submission_handler;
mod async_io;
mod sys;
mod waker;
mod proactor;
mod utils;
mod waker;

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


#[cfg(any(
target_os = "macos",
target_os = "ios",
Expand All @@ -48,4 +47,4 @@ mod syscore {
}

pub use proactor::*;
pub use runtime::runtime::*;
pub use runtime::runtime::*;
56 changes: 26 additions & 30 deletions src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@ macro_rules! runtime_methods {
use std::future::Future;

pub fn spawn<F>(future: F) -> JoinHandle<F::Output>
where
F: Future + Send + 'static,
F::Output: Send + 'static,
where
F: Future + Send + 'static,
F::Output: Send + 'static,
{
RUNTIME.spawn(future)
}

pub fn spawn_blocking<F, T>(task: F) -> JoinHandle<T>
where
F: FnOnce() -> T + Send + 'static,
T: Send + 'static,
where
F: FnOnce() -> T + Send + 'static,
T: Send + 'static,
{
RUNTIME.spawn_blocking(task)
}

pub fn block_on<F>(future: F) -> F::Output
where
F: Future + Send + 'static,
F::Output: Send + 'static,
where
F: Future + Send + 'static,
F::Output: Send + 'static,
{
RUNTIME.block_on(future)
}
Expand All @@ -31,54 +31,50 @@ macro_rules! runtime_methods {

#[cfg(feature = "bastion")]
pub mod runtime {
use agnostik::executors::BastionExecutor;
use agnostik::{Agnostik, AgnostikExecutor};
use once_cell::sync::Lazy;
use agnostik::{AgnostikExecutor, Agnostik};
use agnostik::executors::{BastionExecutor};

static RUNTIME: Lazy<BastionExecutor> = Lazy::new(|| unsafe {
std::mem::transmute(Agnostik::bastion())
});
static RUNTIME: Lazy<BastionExecutor> =
Lazy::new(|| unsafe { std::mem::transmute(Agnostik::bastion()) });

runtime_methods!();
}

#[cfg(feature = "tokio")]
pub mod runtime {
use once_cell::sync::Lazy;
use agnostik::{Agnostik, LocalAgnostikExecutor};
use agnostik::executors::TokioExecutor;
use agnostik::{Agnostik, LocalAgnostikExecutor};
use once_cell::sync::Lazy;

static RUNTIME: Lazy<TokioExecutor> = Lazy::new(|| unsafe {
std::mem::transmute(Agnostik::tokio())
});
static RUNTIME: Lazy<TokioExecutor> =
Lazy::new(|| unsafe { std::mem::transmute(Agnostik::tokio()) });

runtime_methods!();
}

#[cfg(feature = "asyncstd")]
pub mod runtime {
use once_cell::sync::Lazy;
use agnostik::{Agnostik, LocalAgnostikExecutor};
use agnostik::executors::AsyncStdExecutor;
use agnostik::{Agnostik, LocalAgnostikExecutor};
use once_cell::sync::Lazy;

static RUNTIME: Lazy<AsyncStdExecutor> = Lazy::new(|| unsafe {
std::mem::transmute(Agnostik::async_std())
});
static RUNTIME: Lazy<AsyncStdExecutor> =
Lazy::new(|| unsafe { std::mem::transmute(Agnostik::async_std()) });

runtime_methods!();
}

#[cfg(feature = "smol")]
pub mod runtime {
use once_cell::sync::Lazy;
use agnostik::{Agnostik, LocalAgnostikExecutor};
use agnostik::executors::SmolExecutor;
use agnostik::{Agnostik, LocalAgnostikExecutor};
use once_cell::sync::Lazy;

static RUNTIME: Lazy<SmolExecutor> = Lazy::new(|| unsafe {
std::mem::transmute(Agnostik::smol())
});
static RUNTIME: Lazy<SmolExecutor> =
Lazy::new(|| unsafe { std::mem::transmute(Agnostik::smol()) });

runtime_methods!();
}

pub use runtime::*;
pub use runtime::*;
25 changes: 14 additions & 11 deletions src/submission_handler.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
use futures::io::{
AsyncRead, AsyncWrite, AsyncBufRead, AsyncSeek
};
use std::marker::PhantomData as marker;
use std::{task::{Context, Poll}, io, pin::Pin, future::Future, ops::{DerefMut, Deref}};
use super::handle::{Handle, HandleOpRegisterer};

use futures::io::{AsyncBufRead, AsyncRead, AsyncSeek, AsyncWrite};
use std::marker::PhantomData as marker;
use std::{
future::Future,
io,
ops::{Deref, DerefMut},
pin::Pin,
task::{Context, Poll},
};

pub struct SubmissionHandler<T>(marker<T>)
where
T: Unpin;
T: Unpin;

impl<T> SubmissionHandler<T>
where
T: Unpin + HandleOpRegisterer
T: Unpin + HandleOpRegisterer,
{
pub fn handle_read(
handle: Pin<&mut T>,
cx: &mut Context,
completion_dispatcher: impl Future<Output=io::Result<usize>> + 'static
completion_dispatcher: impl Future<Output = io::Result<usize>> + 'static,
) -> Poll<io::Result<usize>> {
let handle = handle.get_mut();
let read_result = handle.read_registerer();
Expand Down Expand Up @@ -46,7 +49,7 @@ where
pub fn handle_write(
handle: Pin<&mut T>,
cx: &mut Context,
completion_dispatcher: impl Future<Output=io::Result<usize>> + 'static
completion_dispatcher: impl Future<Output = io::Result<usize>> + 'static,
) -> Poll<io::Result<usize>> {
let handle = handle.get_mut();
let write_result = handle.write_registerer();
Expand All @@ -71,4 +74,4 @@ where

poll
}
}
}
Loading

0 comments on commit 1b28531

Please sign in to comment.