shio rs
1.0.0
Shio是生锈的快速,简单和异步的微型网络框架。
异步。处理程序都是异步处理的,并且本身可能是异步的。 shio::Handler接收tokio_core::reactor::Handle该操作可用于安排线程 - 本地事件循环中的其他工作。
多线程。默认情况下,请求由多个线程处理,每个线程都运行由tokio提供动力的事件循环。
稳定。 Shio完全致力于工作,并继续从事稳定的生锈工作。
[ dependencies ]
shio = " 0.2.0 " extern crate shio ;
use shio :: prelude :: * ;
fn hello_world ( _ : Context ) -> Response {
Response :: with ( "Hello World! n " )
}
fn hello ( ctx : Context ) -> Response {
Response :: with ( format ! ( "Hello, {}! n " , & ctx . get :: < Parameters > ( ) [ "name" ] ) )
}
fn main ( ) {
Shio :: default ( )
. route ( ( Method :: GET , "/" , hello_world ) )
. route ( ( Method :: GET , "/{name}" , hello ) )
. run ( ":7878" ) . unwrap ( ) ;
} 请求处理程序是实现shio::Handler特征的值。
每个请求都不会克隆处理程序,因此可能包含状态。请注意,必须Send + Sync 。
extern crate shio ;
use std :: thread ;
use std :: sync :: atomic :: { AtomicUsize , Ordering } ;
use shio :: prelude :: * ;
# [ derive ( Default ) ]
struct HandlerWithState {
counter : AtomicUsize ,
}
impl shio :: Handler for HandlerWithState {
type Result = Response ;
fn call ( & self , _ : Context ) -> Self :: Result {
let counter = self . counter . fetch_add ( 1 , Ordering :: Relaxed ) ;
Response :: with ( format ! (
"Hi, #{} (from thread: {:?}) n " ,
counter ,
thread :: current ( ) . id ( )
) )
}
}Shio包含更多的用法示例/。
示例可以使用cargo run -p <example name>运行。例如,要运行hello示例,请使用:
$ cargo run -p hello根据任何一个
可以选择。
除非您另有明确说明,否则任何有意提交的捐款(如Apache-2.0许可证中定义)应为双重许可,如上所述,没有任何其他条款或条件。