Skip to content

Commit b3e3be5

Browse files
committed
upstream docs
1 parent ea496f2 commit b3e3be5

4 files changed

Lines changed: 91 additions & 96 deletions

File tree

cot-core/src/handler.rs

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -239,35 +239,4 @@ pub use handle_all_parameters;
239239
handle_all_parameters!(impl_request_handler);
240240
handle_all_parameters_from_request!(impl_request_handler_from_request);
241241

242-
#[rustfmt::skip] // `wrap_comments` breaks local links
243-
/// A wrapper around a handler that's used in
244-
/// [`Bootstrapper`](../../cot/project/struct.Bootstrapper.html).
245-
///
246-
/// It is returned by
247-
/// [`Bootstrapper::finish()`](../../cot/project/struct.Bootstrapper.html#method.finish).
248-
/// Typically, you don't need to interact with this type directly, except
249-
/// for creating it in
250-
/// [`Project::middlewares()`](../../cot/project/trait.Project.html#method.middlewares) through the
251-
/// [`RootHandlerBuilder::build()`](../../cot/project/struct.RootHandlerBuilder.html#method.build)
252-
/// method.
253-
///
254-
/// # Examples
255-
///
256-
/// ```
257-
/// use cot::config::ProjectConfig;
258-
/// use cot::{Bootstrapper, BoxedHandler, Project};
259-
///
260-
/// struct MyProject;
261-
/// impl Project for MyProject {}
262-
///
263-
/// # #[tokio::main]
264-
/// # async fn main() -> cot::Result<()> {
265-
/// let bootstrapper = Bootstrapper::new(MyProject)
266-
/// .with_config(ProjectConfig::default())
267-
/// .boot()
268-
/// .await?;
269-
/// let handler: BoxedHandler = bootstrapper.finish().handler;
270-
/// # Ok(())
271-
/// # }
272-
/// ```
273242
pub type BoxedHandler = BoxCloneSyncService<Request, Response, Error>;

cot-core/src/middleware.rs

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -17,37 +17,6 @@ use crate::request::Request;
1717
use crate::response::Response;
1818
use crate::{Body, Error};
1919

20-
#[rustfmt::skip] // `wrap_comments` breaks local links
21-
/// Middleware that converts any [`http::Response`] generic type
22-
/// to a [`Response`].
23-
///
24-
/// This is useful for converting a response from a middleware that is
25-
/// compatible with the `tower` crate to a response that is compatible with
26-
/// Cot. It's applied automatically by
27-
/// [`RootHandlerBuilder::middleware()`](../../cot/project/struct.RootHandlerBuilder.html#method.middleware)
28-
/// and is not needed to be added manually.
29-
///
30-
/// # Examples
31-
///
32-
/// ```
33-
/// use cot::Project;
34-
/// use cot::middleware::LiveReloadMiddleware;
35-
/// use cot::project::{MiddlewareContext, RootHandler, RootHandlerBuilder};
36-
///
37-
/// struct MyProject;
38-
/// impl Project for MyProject {
39-
/// fn middlewares(
40-
/// &self,
41-
/// handler: RootHandlerBuilder,
42-
/// context: &MiddlewareContext,
43-
/// ) -> RootHandler {
44-
/// handler
45-
/// // IntoCotResponseLayer used internally in middleware()
46-
/// .middleware(LiveReloadMiddleware::from_context(context))
47-
/// .build()
48-
/// }
49-
/// }
50-
/// ```
5120
#[derive(Debug, Copy, Clone)]
5221
pub struct IntoCotResponseLayer;
5322

@@ -132,36 +101,6 @@ where
132101
response.map(|body| Body::wrapper(BoxBody::new(body.map_err(map_err))))
133102
}
134103

135-
#[rustfmt::skip] // `wrap_comments` breaks local links
136-
/// Middleware that converts any error type to [`Error`].
137-
///
138-
/// This is useful for converting a response from a middleware that is
139-
/// compatible with the `tower` crate to a response that is compatible with
140-
/// Cot. It's applied automatically by
141-
/// [`RootHandlerBuilder::middleware`](../../cot/project/struct.RootHandlerBuilder.html#method.middleware)
142-
/// and is not needed to be added manually.
143-
///
144-
/// # Examples
145-
///
146-
/// ```
147-
/// use cot::Project;
148-
/// use cot::middleware::LiveReloadMiddleware;
149-
/// use cot::project::{MiddlewareContext, RootHandler, RootHandlerBuilder};
150-
///
151-
/// struct MyProject;
152-
/// impl Project for MyProject {
153-
/// fn middlewares(
154-
/// &self,
155-
/// handler: RootHandlerBuilder,
156-
/// context: &MiddlewareContext,
157-
/// ) -> RootHandler {
158-
/// handler
159-
/// // IntoCotErrorLayer used internally in middleware()
160-
/// .middleware(LiveReloadMiddleware::from_context(context))
161-
/// .build()
162-
/// }
163-
/// }
164-
/// ```
165104
#[derive(Debug, Copy, Clone)]
166105
pub struct IntoCotErrorLayer;
167106

cot/src/lib.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,35 @@ pub use schemars;
161161
pub use {bytes, http};
162162

163163
pub use crate::__private::askama::{Template, filter_fn};
164-
pub use crate::handler::{BoxedHandler, RequestHandler};
164+
/// A wrapper around a handler that's used in [`Bootstrapper`].
165+
///
166+
/// It is returned by [`Bootstrapper::finish`]. Typically, you don't need to
167+
/// interact with this type directly, except for creating it in
168+
/// [`Project::middlewares`] through the
169+
/// [`RootHandlerBuilder::build`](crate::project::RootHandlerBuilder::build)
170+
/// method.
171+
///
172+
/// # Examples
173+
///
174+
/// ```
175+
/// use cot::config::ProjectConfig;
176+
/// use cot::{Bootstrapper, BoxedHandler, Project};
177+
///
178+
/// struct MyProject;
179+
/// impl Project for MyProject {}
180+
///
181+
/// # #[tokio::main]
182+
/// # async fn main() -> cot::Result<()> {
183+
/// let bootstrapper = Bootstrapper::new(MyProject)
184+
/// .with_config(ProjectConfig::default())
185+
/// .boot()
186+
/// .await?;
187+
/// let handler: BoxedHandler = bootstrapper.finish().handler;
188+
/// # Ok(())
189+
/// # }
190+
/// ```
191+
pub use crate::handler::BoxedHandler;
192+
pub use crate::handler::RequestHandler;
165193
pub use crate::project::{
166194
App, AppBuilder, Bootstrapper, Project, ProjectContext, run, run_at, run_cli,
167195
};

cot/src/middleware.rs

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,69 @@ use crate::session::store::redis::RedisStore;
3333
#[cfg(feature = "live-reload")]
3434
mod live_reload;
3535

36+
/// Middleware that converts any error type to [`Error`].
37+
///
38+
/// This is useful for converting a response from a middleware that is
39+
/// compatible with the `tower` crate to a response that is compatible with
40+
/// Cot. It's applied automatically by
41+
/// [`RootHandlerBuilder::middleware`](crate::project::RootHandlerBuilder::middleware) and is not needed to be added
42+
/// manually.
43+
///
44+
/// # Examples
45+
///
46+
/// ```
47+
/// use cot::Project;
48+
/// use cot::middleware::LiveReloadMiddleware;
49+
/// use cot::project::{MiddlewareContext, RootHandler, RootHandlerBuilder};
50+
///
51+
/// struct MyProject;
52+
/// impl Project for MyProject {
53+
/// fn middlewares(
54+
/// &self,
55+
/// handler: RootHandlerBuilder,
56+
/// context: &MiddlewareContext,
57+
/// ) -> RootHandler {
58+
/// handler
59+
/// // IntoCotErrorLayer used internally in middleware()
60+
/// .middleware(LiveReloadMiddleware::from_context(context))
61+
/// .build()
62+
/// }
63+
/// }
64+
/// ```
65+
pub use cot_core::middleware::IntoCotErrorLayer;
66+
/// Middleware that converts any `http::Response` generic type
67+
/// to a [`Response`].
68+
///
69+
/// This is useful for converting a response from a middleware that is
70+
/// compatible with the `tower` crate to a response that is compatible with
71+
/// Cot. It's applied automatically by
72+
/// [`RootHandlerBuilder::middleware`](crate::project::RootHandlerBuilder::middleware)
73+
/// and is not needed to be added manually.
74+
///
75+
/// # Examples
76+
///
77+
/// ```
78+
/// use cot::Project;
79+
/// use cot::middleware::LiveReloadMiddleware;
80+
/// use cot::project::{MiddlewareContext, RootHandler, RootHandlerBuilder};
81+
///
82+
/// struct MyProject;
83+
/// impl Project for MyProject {
84+
/// fn middlewares(
85+
/// &self,
86+
/// handler: RootHandlerBuilder,
87+
/// context: &MiddlewareContext,
88+
/// ) -> RootHandler {
89+
/// handler
90+
/// // IntoCotResponseLayer used internally in middleware()
91+
/// .middleware(LiveReloadMiddleware::from_context(context))
92+
/// .build()
93+
/// }
94+
/// }
95+
/// ```
96+
pub use cot_core::middleware::IntoCotResponseLayer;
3697
#[doc(inline)]
37-
pub use cot_core::middleware::{
38-
IntoCotError, IntoCotErrorLayer, IntoCotResponse, IntoCotResponseLayer,
39-
};
98+
pub use cot_core::middleware::{IntoCotError, IntoCotResponse};
4099
#[cfg(feature = "live-reload")]
41100
pub use live_reload::LiveReloadMiddleware;
42101

0 commit comments

Comments
 (0)