src/server/formatter.rs: rename format_result to format_data

To avoid confusions with Rust Result type.
This commit is contained in:
Dietmar Maurer 2019-05-09 13:15:15 +02:00
parent 21ee7912fa
commit d55037e471
2 changed files with 6 additions and 6 deletions

View File

@ -11,7 +11,7 @@ pub struct ErrorMessageExtension(pub String);
pub struct OutputFormatter { pub struct OutputFormatter {
pub format_result: fn(data: Value, rpcenv: &RpcEnvironment) -> Response<Body>, pub format_data: fn(data: Value, rpcenv: &RpcEnvironment) -> Response<Body>,
pub format_error: fn(err: Error) -> Response<Body>, pub format_error: fn(err: Error) -> Response<Body>,
} }
@ -33,7 +33,7 @@ pub fn json_response(result: Value) -> Response<Body> {
response response
} }
fn json_format_result(data: Value, rpcenv: &RpcEnvironment) -> Response<Body> { fn json_format_data(data: Value, rpcenv: &RpcEnvironment) -> Response<Body> {
let mut result = json!({ let mut result = json!({
"data": data "data": data
@ -72,11 +72,11 @@ pub fn json_format_error(err: Error) -> Response<Body> {
} }
pub static JSON_FORMATTER: OutputFormatter = OutputFormatter { pub static JSON_FORMATTER: OutputFormatter = OutputFormatter {
format_result: json_format_result, format_data: json_format_data,
format_error: json_format_error, format_error: json_format_error,
}; };
fn extjs_format_result(data: Value, rpcenv: &RpcEnvironment) -> Response<Body> { fn extjs_format_data(data: Value, rpcenv: &RpcEnvironment) -> Response<Body> {
let mut result = json!({ let mut result = json!({
"data": data, "data": data,
@ -116,6 +116,6 @@ fn extjs_format_error(err: Error) -> Response<Body> {
} }
pub static EXTJS_FORMATTER: OutputFormatter = OutputFormatter { pub static EXTJS_FORMATTER: OutputFormatter = OutputFormatter {
format_result: extjs_format_result, format_data: extjs_format_data,
format_error: extjs_format_error, format_error: extjs_format_error,
}; };

View File

@ -240,7 +240,7 @@ pub fn handle_sync_api_request<Env: RpcEnvironment>(
.and_then(move |params| { .and_then(move |params| {
let mut delay = false; let mut delay = false;
let resp = match (info.handler.as_ref().unwrap())(params, info, &mut rpcenv) { let resp = match (info.handler.as_ref().unwrap())(params, info, &mut rpcenv) {
Ok(data) => (formatter.format_result)(data, &rpcenv), Ok(data) => (formatter.format_data)(data, &rpcenv),
Err(err) => { Err(err) => {
if let Some(httperr) = err.downcast_ref::<HttpError>() { if let Some(httperr) = err.downcast_ref::<HttpError>() {
if httperr.code == StatusCode::UNAUTHORIZED { delay = true; } if httperr.code == StatusCode::UNAUTHORIZED { delay = true; }