Skip to content

Commit

Permalink
Add prelude (#567)
Browse files Browse the repository at this point in the history
  • Loading branch information
msrd0 committed Nov 12, 2021
1 parent ca0f906 commit 6238958
Show file tree
Hide file tree
Showing 42 changed files with 126 additions and 124 deletions.
6 changes: 3 additions & 3 deletions examples/cookies/introduction/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use gotham::hyper::{Body, Response, StatusCode};
use gotham::middleware::cookie::CookieParser;
use gotham::mime::TEXT_PLAIN;
use gotham::pipeline::{new_pipeline, single_pipeline};
use gotham::router::builder::*;
use gotham::router::Router;
use gotham::state::{FromState, State};
use gotham::prelude::*;
use gotham::router::{build_router, Router};
use gotham::state::State;

/// The first request will set a cookie, and subsequent requests will echo it back.
fn handler(state: State) -> (State, Response<Body>) {
Expand Down
4 changes: 2 additions & 2 deletions examples/custom_service/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use futures_util::future::{BoxFuture, FutureExt};
use gotham::hyper::server::conn::Http;
use gotham::hyper::service::Service;
use gotham::hyper::{Body, Request, Response};
use gotham::router::builder::*;
use gotham::router::Router;
use gotham::prelude::*;
use gotham::router::{build_simple_router, Router};
use gotham::service::call_handler;
use gotham::state::State;
use std::net::SocketAddr;
Expand Down
8 changes: 4 additions & 4 deletions examples/diesel/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ extern crate diesel_migrations;
use diesel::prelude::*;
use diesel::sqlite::SqliteConnection;
use futures_util::FutureExt;
use gotham::handler::{HandlerError, HandlerFuture, MapHandlerError, MapHandlerErrorFuture};
use gotham::handler::{HandlerError, HandlerFuture};
use gotham::helpers::http::response::create_response;
use gotham::hyper::{body, Body, StatusCode};
use gotham::mime::APPLICATION_JSON;
use gotham::pipeline::{new_pipeline, single_pipeline};
use gotham::router::builder::*;
use gotham::router::Router;
use gotham::state::{FromState, State};
use gotham::prelude::*;
use gotham::router::{build_router, Router};
use gotham::state::State;
use gotham_middleware_diesel::DieselMiddleware;
use serde::Serialize;
use std::pin::Pin;
Expand Down
4 changes: 2 additions & 2 deletions examples/example_contribution_template/name/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
//! you're writing an example for setting Cookies.
use gotham::helpers::http::response::create_empty_response;
use gotham::hyper::{Body, Response, StatusCode};
use gotham::router::builder::*;
use gotham::router::Router;
use gotham::prelude::*;
use gotham::router::{build_simple_router, Router};
use gotham::state::State;

/// Create a `Handler` that ...
Expand Down
4 changes: 2 additions & 2 deletions examples/finalizers/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! An finalizer example
use gotham::hyper::body::Body;
use gotham::hyper::{Response, StatusCode};
use gotham::router::builder::*;
use gotham::prelude::*;
use gotham::router::response::ResponseExtender;
use gotham::router::Router;
use gotham::router::{build_simple_router, Router};
use gotham::state::State;

const HELLO_ROUTER: &str = "Hello Router!";
Expand Down
6 changes: 3 additions & 3 deletions examples/handlers/async_handlers/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ use gotham::hyper::StatusCode;
#[cfg(not(test))]
use gotham::hyper::{body, Client, Uri};
use gotham::mime::TEXT_PLAIN;
use gotham::router::builder::{build_simple_router, DefineSingleRoute, DrawRoutes};
use gotham::router::response::StaticResponseExtender;
use gotham::prelude::*;
use gotham::router::builder::build_simple_router;
use gotham::router::Router;
use gotham::state::{FromState, State, StateData};
use gotham::state::State;

type ResponseContentFuture =
Pin<Box<dyn Future<Output = Result<Vec<u8>, gotham::hyper::Error>> + Send>>;
Expand Down
10 changes: 6 additions & 4 deletions examples/handlers/form_urlencoded/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
//! An example of decoding requests from an HTML form element

use futures_util::future::{self, FutureExt};
use std::pin::Pin;
use url::form_urlencoded;

use gotham::handler::HandlerFuture;
use gotham::helpers::http::response::create_response;
use gotham::hyper::{body, Body, StatusCode};
use gotham::mime::TEXT_PLAIN;
use gotham::router::builder::{build_simple_router, DefineSingleRoute, DrawRoutes};
use gotham::prelude::*;
use gotham::router::builder::build_simple_router;
use gotham::router::Router;
use gotham::state::{FromState, State};
use std::pin::Pin;
use url::form_urlencoded;
use gotham::state::State;

/// Extracts the elements of the POST request and responds with the form keys and values
fn form_handler(mut state: State) -> Pin<Box<HandlerFuture>> {
Expand Down
5 changes: 3 additions & 2 deletions examples/handlers/multipart/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ use gotham::helpers::http::response::create_response;
use gotham::hyper::header::CONTENT_TYPE;
use gotham::hyper::{body, Body, HeaderMap, StatusCode};
use gotham::mime::TEXT_PLAIN;
use gotham::router::builder::{build_simple_router, DefineSingleRoute, DrawRoutes};
use gotham::prelude::*;
use gotham::router::builder::build_simple_router;
use gotham::router::Router;
use gotham::state::{FromState, State};
use gotham::state::State;
use multipart::server::Multipart;
use std::io::{Cursor, Read};
use std::pin::Pin;
Expand Down
7 changes: 4 additions & 3 deletions examples/handlers/request_data/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
//! A basic example showing the request components
use futures_util::future::{self, FutureExt};
use gotham::hyper::{body, Body, HeaderMap, Method, Response, StatusCode, Uri, Version};
use std::pin::Pin;

use gotham::handler::HandlerFuture;
use gotham::helpers::http::response::create_empty_response;
use gotham::router::builder::{build_simple_router, DefineSingleRoute, DrawRoutes};
use gotham::hyper::{body, Body, HeaderMap, Method, Response, StatusCode, Uri, Version};
use gotham::prelude::*;
use gotham::router::builder::build_simple_router;
use gotham::router::Router;
use gotham::state::{FromState, State};
use gotham::state::State;

/// Extract the main elements of the request except for the `Body`
fn print_request_elements(state: &State) {
Expand Down
6 changes: 3 additions & 3 deletions examples/handlers/simple_async_handlers/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ use gotham::handler::HandlerFuture;
use gotham::helpers::http::response::create_response;
use gotham::hyper::StatusCode;
use gotham::mime::TEXT_PLAIN;
use gotham::router::builder::{build_simple_router, DefineSingleRoute, DrawRoutes};
use gotham::router::response::StaticResponseExtender;
use gotham::prelude::*;
use gotham::router::builder::build_simple_router;
use gotham::router::Router;
use gotham::state::{FromState, State, StateData};
use gotham::state::State;

#[derive(Deserialize, StateData, StaticResponseExtender)]
struct QueryStringExtractor {
Expand Down
8 changes: 4 additions & 4 deletions examples/handlers/simple_async_handlers_await/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//! A basic example showing the request components

use gotham::handler::{HandlerError, HandlerResult, IntoResponse};
use gotham::handler::{HandlerError, HandlerResult};
use gotham::helpers::http::response::create_response;
use gotham::hyper::{Body, StatusCode};
use gotham::mime::TEXT_PLAIN;
use gotham::router::builder::{build_simple_router, DefineSingleRoute, DrawRoutes};
use gotham::router::response::StaticResponseExtender;
use gotham::prelude::*;
use gotham::router::builder::build_simple_router;
use gotham::router::Router;
use gotham::state::{FromState, State, StateData};
use gotham::state::State;
use serde::Deserialize;
use std::time::Duration;
use tokio::time::sleep;
Expand Down
10 changes: 5 additions & 5 deletions examples/handlers/stateful/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ use std::pin::Pin;
use std::sync::{Arc, Mutex};
use std::time::SystemTime;

use gotham::anyhow::Result;
use gotham::handler::{Handler, HandlerFuture, IntoResponse, NewHandler};
use gotham::router::builder::*;
use gotham::router::Router;
use gotham::anyhow;
use gotham::handler::{Handler, HandlerFuture, NewHandler};
use gotham::prelude::*;
use gotham::router::{build_simple_router, Router};
use gotham::state::State;

// A struct which can store the state which it needs.
Expand Down Expand Up @@ -61,7 +61,7 @@ impl Handler for CountingHandler {
impl NewHandler for CountingHandler {
type Instance = Self;

fn new_handler(&self) -> Result<Self::Instance> {
fn new_handler(&self) -> anyhow::Result<Self::Instance> {
Ok(self.clone())
}
}
Expand Down
4 changes: 2 additions & 2 deletions examples/headers/setting/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Setting a header value for a Gotham web framework response
use gotham::helpers::http::response::create_empty_response;
use gotham::hyper::{Body, Response, StatusCode};
use gotham::router::builder::*;
use gotham::router::Router;
use gotham::prelude::*;
use gotham::router::{build_simple_router, Router};
use gotham::state::State;

/// Create a `Handler` that adds a custom header.
Expand Down
5 changes: 2 additions & 3 deletions examples/into_response/introduction/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
//! An introduction to the Gotham web framework's `IntoResponse` trait.

use gotham::handler::IntoResponse;
use gotham::helpers::http::response::create_response;
use gotham::hyper::{Body, Response, StatusCode};
use gotham::mime::APPLICATION_JSON;
use gotham::router::builder::*;
use gotham::router::Router;
use gotham::prelude::*;
use gotham::router::{build_simple_router, Router};
use gotham::state::State;
use serde::Serialize;

Expand Down
8 changes: 4 additions & 4 deletions examples/middleware/introduction/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ use gotham::handler::HandlerFuture;
use gotham::helpers::http::response::create_empty_response;
use gotham::hyper::header::{HeaderMap, USER_AGENT};
use gotham::hyper::{Body, Response, StatusCode};
use gotham::middleware::{Middleware, NewMiddleware};
use gotham::middleware::Middleware;
use gotham::pipeline::{new_pipeline, single_pipeline};
use gotham::router::builder::*;
use gotham::router::Router;
use gotham::state::{FromState, State, StateData};
use gotham::prelude::*;
use gotham::router::{build_router, Router};
use gotham::state::State;

/// A simple struct which holds an identifier for the user agent which made the request.
///
Expand Down
8 changes: 4 additions & 4 deletions examples/middleware/introduction_await/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ use gotham::handler::HandlerFuture;
use gotham::helpers::http::response::create_empty_response;
use gotham::hyper::header::{HeaderMap, USER_AGENT};
use gotham::hyper::{Body, Response, StatusCode};
use gotham::middleware::{Middleware, NewMiddleware};
use gotham::middleware::Middleware;
use gotham::pipeline::{new_pipeline, single_pipeline};
use gotham::router::builder::*;
use gotham::router::Router;
use gotham::state::{FromState, State, StateData};
use gotham::prelude::*;
use gotham::router::{build_router, Router};
use gotham::state::State;

/// A simple struct which holds an identifier for the user agent which made the request.
///
Expand Down
8 changes: 4 additions & 4 deletions examples/middleware/multiple_pipelines/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ use std::pin::Pin;
use gotham::handler::HandlerFuture;
use gotham::helpers::http::response::create_response;
use gotham::middleware::session::NewSessionMiddleware;
use gotham::middleware::{Middleware, NewMiddleware};
use gotham::middleware::Middleware;
use gotham::pipeline::{finalize_pipeline_set, new_pipeline, new_pipeline_set, single_pipeline};
use gotham::router::builder::*;
use gotham::router::Router;
use gotham::state::{FromState, State};
use gotham::prelude::*;
use gotham::router::{build_router, Router};
use gotham::state::State;
use serde::{Deserialize, Serialize};

/// A simple struct to represent our default session data.
Expand Down
7 changes: 3 additions & 4 deletions examples/path/globs/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
//! Shows how to match arbitrarily many path segments.

use gotham::router::builder::*;
use gotham::router::response::StaticResponseExtender;
use gotham::router::Router;
use gotham::state::{FromState, State, StateData};
use gotham::prelude::*;
use gotham::router::{build_simple_router, Router};
use gotham::state::State;
use serde::Deserialize;

#[derive(Deserialize, StateData, StaticResponseExtender)]
Expand Down
7 changes: 3 additions & 4 deletions examples/path/introduction/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
//! An introduction to extracting request path segments, in a type safe way, with the
//! Gotham web framework

use gotham::router::builder::*;
use gotham::router::response::StaticResponseExtender;
use gotham::router::Router;
use gotham::state::{FromState, State, StateData};
use gotham::prelude::*;
use gotham::router::{build_simple_router, Router};
use gotham::state::State;
use serde::Deserialize;

/// Holds data extracted from the Request path.
Expand Down
7 changes: 3 additions & 4 deletions examples/path/regex/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
//! An example of the Gotham web framework `Router` that shows how to use Regex patterns in path segments.

use gotham::router::builder::*;
use gotham::router::response::StaticResponseExtender;
use gotham::router::Router;
use gotham::state::{FromState, State, StateData};
use gotham::prelude::*;
use gotham::router::{build_simple_router, Router};
use gotham::state::State;
use serde::Deserialize;

#[derive(Deserialize, StateData, StaticResponseExtender)]
Expand Down
7 changes: 3 additions & 4 deletions examples/query_string/introduction/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
//! Gotham web framework

use gotham::mime::{Mime, APPLICATION_JSON};
use gotham::router::builder::*;
use gotham::router::response::StaticResponseExtender;
use gotham::router::Router;
use gotham::state::{FromState, State, StateData};
use gotham::prelude::*;
use gotham::router::{build_simple_router, Router};
use gotham::state::State;
use serde::{Deserialize, Serialize};

/// Holds data extracted from the Request query string.
Expand Down
2 changes: 1 addition & 1 deletion examples/routing/associations/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! We've used a macro here for brevity but this is NOT how you would implement a handler in
//! a real world application.

use gotham::handler::IntoResponse;
use gotham::prelude::*;
use gotham::state::State;

macro_rules! generic_handler {
Expand Down
4 changes: 2 additions & 2 deletions examples/routing/associations/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! An example of the Gotham web framework `Router` that shows how to associate multiple handlers
//! to a single path.
use gotham::hyper::Method;
use gotham::router::builder::*;
use gotham::router::Router;
use gotham::prelude::*;
use gotham::router::{build_simple_router, Router};

mod handlers;
use self::handlers::*;
Expand Down
2 changes: 1 addition & 1 deletion examples/routing/http_verbs/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! We've used a macro here for brevity but this is NOT how you would implement a handler in
//! a real world application.

use gotham::handler::IntoResponse;
use gotham::prelude::*;
use gotham::state::State;

macro_rules! generic_handler {
Expand Down
4 changes: 2 additions & 2 deletions examples/routing/http_verbs/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! An example of the Gotham web framework Router that shows how to route requests to handlers
//! based on HTTP verbs.
use gotham::hyper::Method;
use gotham::router::builder::*;
use gotham::router::Router;
use gotham::prelude::*;
use gotham::router::{build_simple_router, Router};

mod handlers;
use self::handlers::*;
Expand Down
4 changes: 2 additions & 2 deletions examples/routing/introduction/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! An introduction to fundamental `Router` and `Router Builder` concepts to create a routing tree.
use gotham::router::builder::*;
use gotham::router::Router;
use gotham::prelude::*;
use gotham::router::{build_simple_router, Router};
use gotham::state::State;

const HELLO_ROUTER: &str = "Hello Router!";
Expand Down
2 changes: 1 addition & 1 deletion examples/routing/scopes/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! We've used a macro here for brevity but this is NOT how you would implement a handler in
//! a real world application.

use gotham::handler::IntoResponse;
use gotham::prelude::*;
use gotham::state::State;

macro_rules! generic_handler {
Expand Down
4 changes: 2 additions & 2 deletions examples/routing/scopes/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! An example of the Gotham web framework `Router` that shows how to combine `Routes`
//! under a common root using scopes.
use gotham::hyper::Method;
use gotham::router::builder::*;
use gotham::router::Router;
use gotham::prelude::*;
use gotham::router::{build_simple_router, Router};

mod handlers;
use self::handlers::*;
Expand Down
6 changes: 3 additions & 3 deletions examples/sessions/custom_data_type/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

use gotham::middleware::session::{NewSessionMiddleware, SessionData};
use gotham::pipeline::{new_pipeline, single_pipeline};
use gotham::router::builder::*;
use gotham::router::Router;
use gotham::state::{FromState, State, StateData};
use gotham::prelude::*;
use gotham::router::{build_router, Router};
use gotham::state::State;
use serde::{Deserialize, Serialize};
use time::format_description::well_known::Rfc3339;
use time::OffsetDateTime;
Expand Down
Loading

0 comments on commit 6238958

Please sign in to comment.