fn req_get(
    m_state: web::Data<Arc<Mutex<ServerState>>>,
    req: HttpRequest,
    (path, body): (web::Path<(String,)>, web::Bytes),
) -> Result<HttpResponse> {
    // decode protobuf msg containing key, into KeyRequest struct
    let res = pbdec_key_req(&body);
    if res.is_err() {
        return err_bad_req();
    }
    let in_msg = res.unwrap();

    // lock runtime-live state data
    let state = m_state.lock().unwrap();
    if state.debug {
        println!("{:?}", req);
    }

    // lookup database index by name (path elem 0)
    let idx: usize;
    match state.name_idx.get(&path.0) {
        None => return err_not_found(),
        Some(r_idx) => idx = *r_idx,
    }

    // attempt to read record from db, based on key (http payload)
    match state.dbs[idx].db.get(in_msg.get_key()) {
        Ok(optval) => match optval {
            Some(val) => ok_binary(val.to_vec()),
            None => err_not_found(), // db: value not found
        },
        Err(_e) => err_500(), // db: error
    }
}
/// GET data item. key in HTTP payload, returns value in HTTP payload.
GET data item. key in HTTP payload, returns value in HTTP payload.
GET data item . key in HTTP payload returns value in HTTP payload .
fn req_get(
    m_state: web::Data<Arc<Mutex<ServerState>>>,
    req: HttpRequest,
    (path, body): (web::Path<(String,)>, web::Bytes),
) -> Result<HttpResponse> {
    // decode protobuf msg containing key, into KeyRequest struct
    let res = pbdec_key_req(&body);
    if res.is_err() {
        return err_bad_req();
    }
    let in_msg = res.unwrap();
    // lock runtime-live state data
    let state = m_state.lock().unwrap();
    if state.debug {
        println!("{:?}", req);
    }
    // lookup database index by name (path elem 0)
    let idx: usize;
    match state.name_idx.get(&path.0) {
        None => return err_not_found(),
        Some(r_idx) => idx = *r_idx,
    }
    // attempt to read record from db, based on key (http payload)
    match state.dbs[idx].db.get(in_msg.get_key()) {
        Ok(optval) => match optval {
            Some(val) => ok_binary(val.to_vec()),
            None => err_not_found(), // db: value not found
        },
        Err(_e) => err_500(), // db: error
    }
}
fn req_get ( m_state : web :: Data < Arc < Mutex < ServerState > > > , req : HttpRequest , ( path , body ) : ( web :: Path < ( String , ) > , web :: Bytes ) , ) -> Result < HttpResponse > { // decode protobuf msg containing key, into KeyRequest struct let res = pbdec_key_req ( & body ) ; if res . is_err ( ) { return err_bad_req ( ) ; } let in_msg = res . unwrap ( ) ; // lock runtime-live state data let state = m_state . lock ( ) . unwrap ( ) ; if state . debug { println ! ( " " req ) ; } // lookup database index by name (path elem 0) let idx : usize ; match state . name_idx . get ( & path . 0 ) { None => return err_not_found ( ) , Some ( r_idx ) => idx = * r_idx , } // attempt to read record from db, based on key (http payload) match state . dbs [ idx ] . db . get ( in_msg . get_key ( ) ) { Ok ( optval ) => match optval { Some ( val ) => ok_binary ( val . to_vec ( ) ) , None => err_not_found ( ) , // db: value not found } , Err ( _e ) => err_500 ( ) , // db: error } }
GET data item.
GET data item .
m_state
web::Data<Arc<Mutex<ServerState>>>
req
(web::Path<(String,)>, web::Bytes)
m_state
web::Data<Arc<Mutex<ServerState>>>
req
(web::Path<(String,)>, web::Bytes)