Struct tusk_rs::server::Server

source ·
pub struct Server<T, V> { /* private fields */ }
Expand description

The core of Tusk, Server is a async/await ready web server.

Server accepts a generic type T. This type is injected into all routes as the final argument.

Implementations§

source§

impl<T: 'static, V: 'static> Server<T, V>

source

pub async fn new( port: i32, database: DatabaseConfig, treatment: Box<fn(_: Request, _: DatabaseConnection, _: Rc<V>) -> Pin<Box<dyn Future<Output = Result<(T, Request, DatabaseConnection), RouteError>>>>>, initialization_data: V ) -> Server<T, V>

Create a new server. Specify a port, DatabaseConfig, and an async function with arguments Request and a PostgresConn (alias for [Object]) and returns T.

source

pub fn enable_debugging(&mut self)

Enable debugging. This will enable printing verbose information. This is useful for debugging queries and other issues.

source

pub fn disable_debugging(&mut self)

Disable debugging. This will disable printing verbose information. This is the default state.

source

pub fn register(&mut self, r: Route<T>)

Register a Route. Routes should NOT be registered after calling Server::start, as all routes are sorted for peformance when start is called.

See Server::register for a better way to register routes.

source

pub fn module(&mut self, prefix: &str, rs: Vec<Route<T>>)

Register many Routes at once. Routes should NOT be registered after calling Server::start, as all routes are sorted for peformance when start is called.

The recommended pattern for this is to break out related routes into their own module and decorate each route with #[route], then export a module function which returns a Vec of all the routes within. Note that this has no effect on performance, this just keeps your code organized.

source

pub fn set_postfix(&mut self, f: fn(_: Response) -> Response)

Add function that can modify all outgoing requests. Useful for setting headers.

source

pub fn set_cors(&mut self, origin: &str, headers: &str)

Set CORS data

source

pub async fn start(&mut self)

Prepares Tusk for serving applications and then begins listening.

source

pub fn handle_options(&self) -> Response

Auto Trait Implementations§

§

impl<T, V> !Freeze for Server<T, V>

§

impl<T, V> !RefUnwindSafe for Server<T, V>

§

impl<T, V> !Send for Server<T, V>

§

impl<T, V> !Sync for Server<T, V>

§

impl<T, V> Unpin for Server<T, V>

§

impl<T, V> !UnwindSafe for Server<T, V>

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> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more