Skip to content

Commit

Permalink
feat: format::html
Browse files Browse the repository at this point in the history
  • Loading branch information
jondot committed Dec 7, 2023
1 parent ee0e73a commit 41c4bc2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Changelog

## vNext

* Added: `format:html` [https://github.com/loco-rs/loco/issues/74](https://github.com/loco-rs/loco/issues/74)

26 changes: 25 additions & 1 deletion src/controller/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
//! }
//! ```
use axum::Json;
use axum::{response::Html, Json};

use crate::Result;

Expand Down Expand Up @@ -96,3 +96,27 @@ pub fn text(t: &str) -> Result<String> {
pub fn json<T>(t: T) -> Result<Json<T>> {
Ok(Json(t))
}

/// Returns an HTML response
///
/// # Example:
///
/// ```rust
/// use loco_rs::{
/// controller::format,
/// Result,
/// };
/// use axum::Html;
///

Check failure on line 110 in src/controller/format.rs

View workflow job for this annotation

GitHub Actions / Run Tests

unresolved import `axum::Html`
/// async fn endpoint() -> Result<Html<String>> {
/// format::html("hello, world")
/// }
/// ```
///
/// # Errors
///
/// Currently this function did't return any error. this is for feature
/// functionality
pub fn html(content: &str) -> Result<Html<String>> {
Ok(Html(content.to_string()))
}

0 comments on commit 41c4bc2

Please sign in to comment.