Engine

Struct Engine 

Source
pub struct Engine { /* private fields */ }
Expand description

The Engine is the main struct of the Runtime.
It drives the runtime Accepting Requests Answering them etc.

Implementations§

Source§

impl Engine

Source

pub fn new(addr: impl ToSocketAddrs) -> Self

Creates a new Engine instance without a config

Source

pub fn with_config(config: EngineConfig) -> Self

Creates a new Engine instance with a config

Source

pub fn spawn(&self, task: impl FnOnce() + Send + 'static)

Add a new task to the internal TaskPool works like thread::spawn but its managed bythe Engine

Source

pub fn shutdown(&self)

Trigger the shutdown flag to stop the Engine. This method will unblock the thread that is waiting for a message. It will also stop the acceptor thread. This method should be called when the Engine is shutting down. Its Called when the Engine is dropped.

Source

pub fn start(&self)

Starts Acceptor thread. This thread will accept incoming connections and push them to the queue. The thread will run until the Engine is shutdown.

Source

pub fn recv(&self) -> IoResult<Request>

Blocks until a message is available to receive. If the queue is empty, it will wait until a message is available. If the queue is unblocked, it will return an error.

Source

pub fn address(&self) -> String

Returns the address the Engine is Bound to.

Source

pub fn unblock(&self)

Unblocks the thread that is waiting for a message. this medhod allows graceful shutdown of the Engine’s Runtime.

Source

pub fn for_each<F>(self, handle: F) -> Result<()>
where F: FnMut(&mut Request) -> Response,

Iterates over incoming requests and handles them using the provided closure. The closure should take a HttpRequest and return a HttpResponse. This method will block until a request is available. It will also handle the response and write it to the stream.

Trait Implementations§

Source§

impl Drop for Engine

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl Freeze for Engine

§

impl !RefUnwindSafe for Engine

§

impl Send for Engine

§

impl Sync for Engine

§

impl Unpin for Engine

§

impl !UnwindSafe for Engine

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.