diff --git a/examples/src/body_types.rs b/examples/src/body_types.rs index c2d518903..0abc79e8d 100644 --- a/examples/src/body_types.rs +++ b/examples/src/body_types.rs @@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize}; use tide::{ error::ResultExt, forms::{self, ExtractForms}, - response, App, Context, EndpointResult, + response, App, Context, }; #[derive(Serialize, Deserialize, Clone, Debug)] @@ -23,13 +23,13 @@ async fn echo_bytes(mut cx: Context<()>) -> Vec { msg } -async fn echo_json(mut cx: Context<()>) -> EndpointResult { +async fn echo_json(mut cx: Context<()>) -> tide::Result { let msg = cx.body_json().await.client_err()?; println!("JSON: {:?}", msg); Ok(response::json(msg)) } -async fn echo_form(mut cx: Context<()>) -> EndpointResult { +async fn echo_form(mut cx: Context<()>) -> tide::Result { let msg = cx.body_form().await?; println!("Form: {:?}", msg); Ok(forms::form(msg)) diff --git a/examples/src/graphql.rs b/examples/src/graphql.rs index a85af2e69..185b57549 100644 --- a/examples/src/graphql.rs +++ b/examples/src/graphql.rs @@ -5,7 +5,7 @@ use http::status::StatusCode; use juniper::graphql_object; use std::sync::{atomic, Arc}; -use tide::{error::ResultExt, response, App, Context, EndpointResult}; +use tide::{error::ResultExt, response, App, Context}; // First, we define `Data` that holds accumulator state. This is accessible as App data in // Tide, and as executor context in Juniper. @@ -42,7 +42,7 @@ type Schema = juniper::RootNode<'static, Query, Mutation>; // Finally, we'll bridge between Tide and Juniper. `GraphQLRequest` from Juniper implements // `Deserialize`, so we use `Json` extractor to deserialize the request body. -async fn handle_graphql(mut cx: Context) -> EndpointResult { +async fn handle_graphql(mut cx: Context) -> tide::Result { let query: juniper::http::GraphQLRequest = cx.body_json().await.client_err()?; let schema = Schema::new(Query, Mutation); let response = query.execute(&schema, cx.state()); diff --git a/examples/src/messages.rs b/examples/src/messages.rs index 4abdadf61..66412d1e3 100644 --- a/examples/src/messages.rs +++ b/examples/src/messages.rs @@ -1,7 +1,7 @@ use http::status::StatusCode; use serde::{Deserialize, Serialize}; use std::sync::Mutex; -use tide::{error::ResultExt, response, App, Context, EndpointResult}; +use tide::{error::ResultExt, response, App, Context}; #[derive(Default)] struct Database { @@ -37,12 +37,12 @@ impl Database { } } -async fn new_message(mut cx: Context) -> EndpointResult { +async fn new_message(mut cx: Context) -> tide::Result { let msg = cx.body_json().await.client_err()?; Ok(cx.state().insert(msg).to_string()) } -async fn set_message(mut cx: Context) -> EndpointResult<()> { +async fn set_message(mut cx: Context) -> tide::Result<()> { let msg = cx.body_json().await.client_err()?; let id = cx.param("id").client_err()?; @@ -53,7 +53,7 @@ async fn set_message(mut cx: Context) -> EndpointResult<()> { } } -async fn get_message(cx: Context) -> EndpointResult { +async fn get_message(cx: Context) -> tide::Result { let id = cx.param("id").client_err()?; if let Some(msg) = cx.state().get(id) { Ok(response::json(msg)) diff --git a/examples/src/multipart_form/mod.rs b/examples/src/multipart_form/mod.rs index 1e7e91b45..80a789efc 100644 --- a/examples/src/multipart_form/mod.rs +++ b/examples/src/multipart_form/mod.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; use std::io::Read; -use tide::{forms::ExtractForms, response, App, Context, EndpointResult}; +use tide::{forms::ExtractForms, response, App, Context}; #[derive(Serialize, Deserialize, Clone)] struct Message { @@ -9,7 +9,7 @@ struct Message { file: Option, } -async fn upload_file(mut cx: Context<()>) -> EndpointResult { +async fn upload_file(mut cx: Context<()>) -> tide::Result { // https://stackoverflow.com/questions/43424982/how-to-parse-multipart-forms-using-abonander-multipart-with-rocket let mut message = Message { key1: None, diff --git a/examples/src/staticfile.rs b/examples/src/staticfile.rs index cf44ccd97..6e005d26c 100644 --- a/examples/src/staticfile.rs +++ b/examples/src/staticfile.rs @@ -6,7 +6,7 @@ use http::{ StatusCode, }; use http_service::Body; -use tide::{App, Context, EndpointResult, Response}; +use tide::{App, Context, Response}; use std::path::{Component, Path, PathBuf}; use std::{fs, io}; @@ -106,7 +106,7 @@ impl StaticFile { } } -async fn handle_path(ctx: Context) -> EndpointResult { +async fn handle_path(ctx: Context) -> tide::Result { let path = ctx.uri().path(); ctx.state() .stream_bytes(path, ctx.headers()) diff --git a/tide-core/src/app.rs b/tide-core/src/app.rs index ef65b35ad..a1134947c 100644 --- a/tide-core/src/app.rs +++ b/tide-core/src/app.rs @@ -49,12 +49,12 @@ use crate::{ /// /// use tide::error::ResultExt; /// -/// async fn hello(cx: tide::Context<()>) -> tide::EndpointResult { +/// async fn hello(cx: tide::Context<()>) -> tide::Result { /// let user: String = cx.param("user").client_err()?; /// Ok(format!("Hello, {}!", user)) /// } /// -/// async fn goodbye(cx: tide::Context<()>) -> tide::EndpointResult { +/// async fn goodbye(cx: tide::Context<()>) -> tide::Result { /// let user: String = cx.param("user").client_err()?; /// Ok(format!("Goodbye, {}.", user)) /// } @@ -81,7 +81,7 @@ use crate::{ /// use http::status::StatusCode; /// use serde::{Deserialize, Serialize}; /// use std::sync::Mutex; -/// use tide::{error::ResultExt, response, App, Context, EndpointResult}; +/// use tide::{error::ResultExt, response, App, Context}; /// /// #[derive(Default)] /// struct Database { @@ -106,12 +106,12 @@ use crate::{ /// } /// } /// -/// async fn new_message(mut cx: Context) -> EndpointResult { +/// async fn new_message(mut cx: Context) -> tide::Result { /// let msg = cx.body_json().await.client_err()?; /// Ok(cx.state().insert(msg).to_string()) /// } /// -/// async fn get_message(cx: Context) -> EndpointResult { +/// async fn get_message(cx: Context) -> tide::Result { /// let id = cx.param("id").client_err()?; /// if let Some(msg) = cx.state().get(id) { /// Ok(response::json(msg)) diff --git a/tide-core/src/error.rs b/tide-core/src/error.rs index d7e748b6b..b608fa098 100644 --- a/tide-core/src/error.rs +++ b/tide-core/src/error.rs @@ -21,7 +21,7 @@ macro_rules! err_fmt { } /// A convenient `Result` instantiation appropriate for most endpoints. -pub type EndpointResult> = Result; +pub type Result> = std::result::Result; /// A generic endpoint error, which can be converted into a response. #[derive(Debug)] @@ -67,27 +67,27 @@ impl ResponseExt for Response { /// Extends the `Result` type with convenient methods for constructing Tide errors. pub trait ResultExt: Sized { - /// Convert to an `EndpointResult`, treating the `Err` case as a client + /// Convert to an `tide::Result`, treating the `Err` case as a client /// error (response code 400). - fn client_err(self) -> EndpointResult { + fn client_err(self) -> Result { self.with_err_status(400) } - /// Convert to an `EndpointResult`, treating the `Err` case as a server + /// Convert to an `tide::Result`, treating the `Err` case as a server /// error (response code 500). - fn server_err(self) -> EndpointResult { + fn server_err(self) -> Result { self.with_err_status(500) } - /// Convert to an `EndpointResult`, wrapping the `Err` case with a custom + /// Convert to an `tide::Result`, wrapping the `Err` case with a custom /// response status. - fn with_err_status(self, status: S) -> EndpointResult + fn with_err_status(self, status: S) -> Result where StatusCode: HttpTryFrom; } impl ResultExt for std::result::Result { - fn with_err_status(self, status: S) -> EndpointResult + fn with_err_status(self, status: S) -> Result where StatusCode: HttpTryFrom, { @@ -99,27 +99,27 @@ impl ResultExt for std::resu /// Extends the `Result` type using `std::error::Error` trait object as the error type with /// convenient methods for constructing Tide errors. pub trait ResultDynErrExt: Sized { - /// Convert to an `EndpointResult`, treating the `Err` case as a client + /// Convert to an `tide::Result`, treating the `Err` case as a client /// error (response code 400). - fn client_err(self) -> EndpointResult { + fn client_err(self) -> Result { self.with_err_status(400) } - /// Convert to an `EndpointResult`, treating the `Err` case as a server + /// Convert to an `tide::Result`, treating the `Err` case as a server /// error (response code 500). - fn server_err(self) -> EndpointResult { + fn server_err(self) -> Result { self.with_err_status(500) } - /// Convert to an `EndpointResult`, wrapping the `Err` case with a custom + /// Convert to an `tide::Result`, wrapping the `Err` case with a custom /// response status. - fn with_err_status(self, status: S) -> EndpointResult + fn with_err_status(self, status: S) -> Result where StatusCode: HttpTryFrom; } impl ResultDynErrExt for std::result::Result> { - fn with_err_status(self, status: S) -> EndpointResult + fn with_err_status(self, status: S) -> Result where StatusCode: HttpTryFrom, { diff --git a/tide-core/src/lib.rs b/tide-core/src/lib.rs index ca0df3282..2981bf644 100644 --- a/tide-core/src/lib.rs +++ b/tide-core/src/lib.rs @@ -31,7 +31,7 @@ pub use crate::{ app::{App, Server}, context::Context, endpoint::Endpoint, - error::{EndpointResult, Error}, + error::{Error, Result}, response::Response, route::Route, }; diff --git a/tide/src/error.rs b/tide/src/error.rs index 25ae1cc4b..cb07ccf06 100644 --- a/tide/src/error.rs +++ b/tide/src/error.rs @@ -1,6 +1,6 @@ use core::pin::Pin; use futures::future::Future; -pub use tide_core::error::{EndpointResult, Error, ResponseExt, ResultExt, StringError}; +pub use tide_core::error::{Error, ResponseExt, Result, ResultExt, StringError}; -pub(crate) type BoxTryFuture = Pin> + Send + 'static>>; +pub(crate) type BoxTryFuture = Pin> + Send + 'static>>; diff --git a/tide/src/lib.rs b/tide/src/lib.rs index 6ef962c0b..ea679b134 100755 --- a/tide/src/lib.rs +++ b/tide/src/lib.rs @@ -41,8 +41,6 @@ pub mod middleware; pub mod querystring; #[doc(inline)] -pub use tide_core::{ - response, App, Context, Endpoint, EndpointResult, Error, Response, Route, Server, -}; +pub use tide_core::{response, App, Context, Endpoint, Error, Response, Result, Route, Server}; pub use http;