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 라이센스에 정의 된대로 귀하가 작업에 포함시키기 위해 의도적으로 제출 된 모든 기부금은 추가 이용 약관이나 조건없이 위와 같이 이중 라이센스를받습니다.