router: no need to use Fn (fn also works for static closures)
This commit is contained in:
		@ -8,7 +8,7 @@ pub struct ApiMethod {
 | 
			
		||||
    pub description: &'static str,
 | 
			
		||||
    pub parameters: Schema,
 | 
			
		||||
    pub returns: Schema,
 | 
			
		||||
    pub handler: Box<Fn(Value, &ApiMethod) -> Result<Value, Error> + Send + Sync>,
 | 
			
		||||
    pub handler: fn(Value, &ApiMethod) -> Result<Value, Error>,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub enum SubRoute {
 | 
			
		||||
 | 
			
		||||
@ -181,7 +181,7 @@ fn handle_sync_api_request(
 | 
			
		||||
            tokio::spawn(task);
 | 
			
		||||
             */
 | 
			
		||||
 | 
			
		||||
            let res = (*info.handler)(params, info)?;
 | 
			
		||||
            let res = (info.handler)(params, info)?;
 | 
			
		||||
 | 
			
		||||
            Ok(res)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -32,16 +32,16 @@ pub fn router() -> Router {
 | 
			
		||||
            description: "Another Endpoint.",
 | 
			
		||||
            parameters: parameter!{},
 | 
			
		||||
            returns: Schema::Null,
 | 
			
		||||
            handler: Box::new(|param, _info| {
 | 
			
		||||
            handler: |param, _info| {
 | 
			
		||||
                println!("This is a clousure handler: {}", param);
 | 
			
		||||
 | 
			
		||||
                Ok(json!(null))
 | 
			
		||||
           })
 | 
			
		||||
           },
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
    let route2 = Router::new()
 | 
			
		||||
        .get(ApiMethod {
 | 
			
		||||
            handler: Box::new(test_sync_api_handler),
 | 
			
		||||
            handler: test_sync_api_handler,
 | 
			
		||||
            description: "This is a simple test.",
 | 
			
		||||
            parameters: parameter!{
 | 
			
		||||
                force => Boolean!{
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user