pub struct AFast<T, H>{
pub middleware: Arc<Box<Middleware<T, H>>>,
/* private fields */
}Expand description
Core AFast service struct.
Maintains shared state and registered handlers.
Fields§
§middleware: Arc<Box<Middleware<T, H>>>Middleware function
Implementations§
Source§impl<T, H> AFast<T, H>
impl<T, H> AFast<T, H>
Sourcepub fn new(state: T) -> Self
pub fn new(state: T) -> Self
Create a new AFast service instance
§Arguments
state- Shared application statehandlers- List of registered handlers
§Returns
A new AFast instance
Examples found in repository?
examples/test.rs (line 104)
101async fn main() {
102 let state = "".to_string();
103
104 let server = AFast::<String, Header>::new(state)
105 .service("user", "User service", register! { get_user, get_id })
106 .middleware(auth);
107
108 server
109 .serve(
110 #[cfg(feature = "tcp")]
111 &"127.0.0.1:8080",
112 #[cfg(any(feature = "http", feature = "ws"))]
113 &"127.0.0.1:8081",
114 )
115 .await
116 .unwrap();
117}Sourcepub fn middleware(self, middleware: fn() -> Box<Middleware<T, H>>) -> Self
pub fn middleware(self, middleware: fn() -> Box<Middleware<T, H>>) -> Self
Examples found in repository?
examples/test.rs (line 106)
101async fn main() {
102 let state = "".to_string();
103
104 let server = AFast::<String, Header>::new(state)
105 .service("user", "User service", register! { get_user, get_id })
106 .middleware(auth);
107
108 server
109 .serve(
110 #[cfg(feature = "tcp")]
111 &"127.0.0.1:8080",
112 #[cfg(any(feature = "http", feature = "ws"))]
113 &"127.0.0.1:8081",
114 )
115 .await
116 .unwrap();
117}Sourcepub fn service(
self,
name: &str,
desc: &str,
handlers: Vec<HandlerGeneric<T, H>>,
) -> Self
pub fn service( self, name: &str, desc: &str, handlers: Vec<HandlerGeneric<T, H>>, ) -> Self
Register a service with additional handlers
Examples found in repository?
examples/test.rs (line 105)
101async fn main() {
102 let state = "".to_string();
103
104 let server = AFast::<String, Header>::new(state)
105 .service("user", "User service", register! { get_user, get_id })
106 .middleware(auth);
107
108 server
109 .serve(
110 #[cfg(feature = "tcp")]
111 &"127.0.0.1:8080",
112 #[cfg(any(feature = "http", feature = "ws"))]
113 &"127.0.0.1:8081",
114 )
115 .await
116 .unwrap();
117}Sourcepub async fn serve<A: ToSocketAddrs>(&self, addr_http: A) -> Result<(), Error>
pub async fn serve<A: ToSocketAddrs>(&self, addr_http: A) -> Result<(), Error>
Start the server
Depending on feature flags, this will start TCP, HTTP, and/or WebSocket services.
§Arguments
addr_tcp- TCP listening address (only active iftcpfeature enabled)addr_http- HTTP/WebSocket listening address (only active ifhttporwsfeature enabled)
§Returns
Result<(), Error>
Examples found in repository?
examples/test.rs (lines 109-114)
101async fn main() {
102 let state = "".to_string();
103
104 let server = AFast::<String, Header>::new(state)
105 .service("user", "User service", register! { get_user, get_id })
106 .middleware(auth);
107
108 server
109 .serve(
110 #[cfg(feature = "tcp")]
111 &"127.0.0.1:8080",
112 #[cfg(any(feature = "http", feature = "ws"))]
113 &"127.0.0.1:8081",
114 )
115 .await
116 .unwrap();
117}Auto Trait Implementations§
impl<T, H> Freeze for AFast<T, H>where
T: Freeze,
impl<T, H> !RefUnwindSafe for AFast<T, H>
impl<T, H> Send for AFast<T, H>
impl<T, H> Sync for AFast<T, H>
impl<T, H> Unpin for AFast<T, H>where
T: Unpin,
impl<T, H> !UnwindSafe for AFast<T, H>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more