aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2023-04-27 06:24:17 +0000
committerFuwn <[email protected]>2023-04-27 06:24:17 +0000
commit875e201e94ab602eb47cebc3f17cd7ab4ead643c (patch)
tree68710bf3d77e4d3d2ac614fe054f8faf2d6df8a7
parentdocs(rossweisse): add a readme (diff)
downloadwindmark-875e201e94ab602eb47cebc3f17cd7ab4ead643c.tar.xz
windmark-875e201e94ab602eb47cebc3f17cd7ab4ead643c.zip
fix(ci): fix tests and doc examples
-rw-r--r--Makefile.toml5
-rw-r--r--README.md4
-rw-r--r--examples/async.rs3
-rw-r--r--src/router.rs57
4 files changed, 43 insertions, 26 deletions
diff --git a/Makefile.toml b/Makefile.toml
index f921fc6..4bcd761 100644
--- a/Makefile.toml
+++ b/Makefile.toml
@@ -16,6 +16,11 @@ args = ["clippy", "--no-default-features", "--features", "logger,auto-deduce-mim
command = "cargo"
toolchain = "nightly"
+[tasks.test]
+args = ["test", "--no-default-features", "--features", "logger,auto-deduce-mime,response-macros,${@}"]
+command = "cargo"
+toolchain = "1.68.2"
+
[tasks.checkf]
script = '''
#!@shell
diff --git a/README.md b/README.md
index 509afa7..2ef6ca1 100644
--- a/README.md
+++ b/README.md
@@ -44,8 +44,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.set_private_key_file("windmark_private.pem")
.set_certificate_file("windmark_public.pem")
.mount("/", windmark::success!("Hello, World!"))
- .set_error_handler(
- windmark::permanent_failure!("This route does not exist!")
+ .set_error_handler(|_|
+ windmark::Response::permanent_failure("This route does not exist!")
)
.run()
.await
diff --git a/examples/async.rs b/examples/async.rs
index 2c32220..d803ad6 100644
--- a/examples/async.rs
+++ b/examples/async.rs
@@ -20,7 +20,10 @@
#[windmark::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut router = windmark::Router::new();
+ #[cfg(feature = "tokio")]
let async_clicks = std::sync::Arc::new(tokio::sync::Mutex::new(0));
+ #[cfg(feature = "async-std")]
+ let async_clicks = std::sync::Arc::new(async_std::sync::Mutex::new(0));
router.set_private_key_file("windmark_private.pem");
router.set_certificate_file("windmark_public.pem");
diff --git a/src/router.rs b/src/router.rs
index b103197..554651a 100644
--- a/src/router.rs
+++ b/src/router.rs
@@ -200,7 +200,7 @@ impl Router {
///
/// ```rust
/// windmark::Router::new().set_error_handler(|_| {
- /// windmark::success!("You have encountered an error!")
+ /// windmark::Response::success("You have encountered an error!")
/// });
/// ```
pub fn set_error_handler<R>(
@@ -227,9 +227,11 @@ impl Router {
/// # Examples
///
/// ```rust
- /// windmark::Router::new().add_header(|context| {
- /// format!("This is displayed at the top of {}!", context.url.path())
- /// });
+ /// windmark::Router::new().add_header(
+ /// |context: windmark::context::RouteContext| {
+ /// format!("This is displayed at the top of {}!", context.url.path())
+ /// },
+ /// );
/// ```
pub fn add_header(&mut self, handler: impl Partial + 'static) -> &mut Self {
(*self.headers.lock().unwrap()).push(Box::new(handler));
@@ -246,9 +248,11 @@ impl Router {
/// # Examples
///
/// ```rust
- /// windmark::Router::new().add_footer(|context| {
- /// format!("This is displayed at the bottom of {}!", context.url.path())
- /// });
+ /// windmark::Router::new().add_footer(
+ /// |context: windmark::context::RouteContext| {
+ /// format!("This is displayed at the bottom of {}!", context.url.path())
+ /// },
+ /// );
/// ```
pub fn add_footer(&mut self, handler: impl Partial + 'static) -> &mut Self {
(*self.footers.lock().unwrap()).push(Box::new(handler));
@@ -615,12 +619,14 @@ impl Router {
/// ```rust
/// use log::info;
///
- /// windmark::Router::new().set_pre_route_callback(|context| {
- /// info!(
- /// "accepted connection from {}",
- /// context.stream.peer_addr().unwrap().ip(),
- /// )
- /// });
+ /// windmark::Router::new().set_pre_route_callback(
+ /// |context: windmark::context::HookContext| {
+ /// info!(
+ /// "accepted connection from {}",
+ /// context.peer_address.unwrap().ip(),
+ /// )
+ /// },
+ /// );
/// ```
pub fn set_pre_route_callback(
&mut self,
@@ -638,12 +644,15 @@ impl Router {
/// ```rust
/// use log::info;
///
- /// windmark::Router::new().set_post_route_callback(|context, _| {
- /// info!(
- /// "closed connection from {}",
- /// context.stream.peer_addr().unwrap().ip(),
- /// )
- /// });
+ /// windmark::Router::new().set_post_route_callback(
+ /// |context: windmark::context::HookContext,
+ /// _content: &mut windmark::Response| {
+ /// info!(
+ /// "closed connection from {}",
+ /// context.peer_address.unwrap().ip(),
+ /// )
+ /// },
+ /// );
/// ```
pub fn set_post_route_callback(
&mut self,
@@ -731,7 +740,7 @@ impl Router {
/// info!("clicker has been attached!");
/// }
///
- /// async fn on_pre_route(&mut self, context: HookContext<'_>) {
+ /// async fn on_pre_route(&mut self, context: HookContext) {
/// self.clicks += 1;
///
/// info!(
@@ -741,7 +750,7 @@ impl Router {
/// );
/// }
///
- /// async fn on_post_route(&mut self, context: HookContext<'_>) {
+ /// async fn on_post_route(&mut self, context: HookContext) {
/// info!(
/// "clicker has been called post-route on {} with {} clicks!",
/// context.url.path(),
@@ -793,7 +802,7 @@ impl Router {
/// info!("clicker has been attached!");
/// }
///
- /// fn on_pre_route(&mut self, context: HookContext<'_>) {
+ /// fn on_pre_route(&mut self, context: HookContext) {
/// self.clicks += 1;
///
/// info!(
@@ -803,7 +812,7 @@ impl Router {
/// );
/// }
///
- /// fn on_post_route(&mut self, context: HookContext<'_>) {
+ /// fn on_post_route(&mut self, context: HookContext) {
/// info!(
/// "clicker has been called post-route on {} with {} clicks!",
/// context.url.path(),
@@ -854,7 +863,7 @@ impl Router {
/// # Examples
///
/// ```rust
- /// windmark::Router::new().set_languages("en");
+ /// windmark::Router::new().set_languages(["en"]);
/// ```
pub fn set_languages<S>(&mut self, language: impl AsRef<[S]>) -> &mut Self
where S: Into<String> + AsRef<str> {