Move axum-debug crate to workspace (#497)

* add axum-debug to workspace

* update readme

* add changes to changelog

* little docs update

* fix the gap

a tab has leaked into workspace Cargo.toml, it must be fixed

* address clippy warnings
This commit is contained in:
Eray Karatay
2021-11-11 15:18:40 +01:00
committed by GitHub
parent 2507463706
commit f6b47478da
11 changed files with 575 additions and 0 deletions
+15
View File
@@ -0,0 +1,15 @@
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
# Unreleased
- **breaking:** Removed `debug_router` macro.
- **breaking:** Removed `check_service` function.
- **breaking:** Removed `debug_service` function.
# 0.1.0 (6. October 2021)
- Initial release.
+16
View File
@@ -0,0 +1,16 @@
[package]
authors = ["Programatik <[email protected]>"]
categories = ["development-tools::debugging"]
description = "Better error messages for axum framework."
edition = "2018"
homepage = "https://github.com/tokio-rs/axum"
keywords = ["axum", "debugging", "debug"]
license = "MIT"
name = "axum-debug"
readme = "README.md"
repository = "https://github.com/tokio-rs/axum"
version = "0.1.0"
[dependencies]
axum = { path = "../axum" }
axum-debug-macros = { path = "../axum-debug-macros" }
+7
View File
@@ -0,0 +1,7 @@
Copyright 2021 Axum Debug Contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+63
View File
@@ -0,0 +1,63 @@
[![License](https://img.shields.io/crates/l/axum-debug)](https://choosealicense.com/licenses/mit/)
[![Crates.io](https://img.shields.io/crates/v/axum-debug)](https://crates.io/crates/axum-debug)
[![Docs - Stable](https://img.shields.io/crates/v/axum-debug?color=blue&label=docs)](https://docs.rs/axum-debug/)
# axum-debug
This is a debugging crate that provides better error messages for [`axum`]
framework.
[`axum`] is a great framework for developing web applications. But when you
make a mistake, error messages can be really complex and long. It can take a
long time for you to figure out what is wrong in your code. This crate provides
utilities to generate better error messages in case you make a mistake.
## Usage Example
Will fail with a better error message:
```rust
use axum::{routing::get, Router};
use axum_debug::debug_handler;
#[tokio::main]
async fn main() {
let app = Router::new().route("/", get(handler));
axum::Server::bind(&"0.0.0.0:3000".parse().unwrap())
.serve(app.into_make_service())
.await
.unwrap();
}
#[debug_handler]
async fn handler() -> bool {
false
}
```
Error message:
```
error[E0277]: the trait bound `bool: IntoResponse` is not satisfied
--> main.rs:xx:23
|
xx | async fn handler() -> bool {
| ^^^^
| |
| the trait `IntoResponse` is not implemented for `bool`
```
## Safety
This crate uses `#![forbid(unsafe_code)]` to ensure everything is implemented in 100% safe Rust.
## Performance
Macros in this crate have no effect when using release profile. (eg. `cargo build --release`)
## License
This project is licensed under the [MIT license](LICENSE).
[`axum`]: https://crates.io/crates/axum
+104
View File
@@ -0,0 +1,104 @@
//! This is a debugging crate that provides better error messages for [`axum`] framework.
//!
//! [`axum`] is a great framework for developing web applications. But when you make a mistake,
//! error messages can be really complex and long. It can take a long time for you to figure out
//! what is wrong in your code. This crate provides utilities to generate better error messages in
//! case you make a mistake.
//!
//! While using [`axum`], you can get long error messages for simple mistakes. For example:
//!
//! ```rust,compile_fail
//! use axum::{routing::get, Router};
//!
//! #[tokio::main]
//! async fn main() {
//! let app = Router::new().route("/", get(handler));
//!
//! axum::Server::bind(&"0.0.0.0:3000".parse().unwrap())
//! .serve(app.into_make_service())
//! .await
//! .unwrap();
//! }
//!
//! fn handler() -> &'static str {
//! "Hello, world"
//! }
//! ```
//!
//! You will get a long error message about function not implementing [`Handler`] trait. But why
//! this function does not implement it? To figure it out [`debug_handler`] macro can be used.
//!
//! ```rust,compile_fail
//! # use axum::{routing::get, Router};
//! # use axum_debug::debug_handler;
//! #
//! # #[tokio::main]
//! # async fn main() {
//! # let app = Router::new().route("/", get(handler));
//! #
//! # axum::Server::bind(&"0.0.0.0:3000".parse().unwrap())
//! # .serve(app.into_make_service())
//! # .await
//! # .unwrap();
//! # }
//! #
//! #[debug_handler]
//! fn handler() -> &'static str {
//! "Hello, world"
//! }
//! ```
//!
//! ```text
//! error: handlers must be async functions
//! --> main.rs:xx:1
//! |
//! xx | fn handler() -> &'static str {
//! | ^^
//! ```
//!
//! As the error message says, handler function needs to be async.
//!
//! ```rust,compile_fail
//! use axum::{routing::get, Router};
//! use axum_debug::debug_handler;
//!
//! #[tokio::main]
//! async fn main() {
//! let app = Router::new().route("/", get(handler));
//!
//! axum::Server::bind(&"0.0.0.0:3000".parse().unwrap())
//! .serve(app.into_make_service())
//! .await
//! .unwrap();
//! }
//!
//! #[debug_handler]
//! async fn handler() -> &'static str {
//! "Hello, world"
//! }
//! ```
//!
//! # Performance
//!
//! Macros in this crate have no effect when using release profile. (eg. `cargo build --release`)
//!
//! [`axum`]: axum
//! [`Handler`]: axum::handler::Handler
//! [`debug_handler`]: debug_handler
#![warn(
clippy::all,
clippy::dbg_macro,
clippy::todo,
clippy::mem_forget,
rust_2018_idioms,
future_incompatible,
nonstandard_style,
missing_debug_implementations,
missing_docs
)]
#![deny(unreachable_pub, private_in_public)]
#![forbid(unsafe_code)]
pub use axum;
pub use axum_debug_macros::debug_handler;