webrune 0.1.2

A composable web server.
Documentation
use http_body_util::Full;
use hyper::body::Bytes;

/// The HTTP response type used by the framework.
///
/// This is a type alias over [`http::Response`] with a default body type
/// suitable for most responses.
///
/// The default body is a fully-buffered [`Bytes`] payload, but handlers
/// are free to return responses with custom body types if needed.
pub type Response<B = Full<Bytes>> = http::Response<B>;

/// Trait for converting a value into an HTTP [`Response`].
///
/// `IntoResponse` is used to normalize different return types from handlers
/// into a concrete response that can be sent to the client.
///
/// This allows handlers to return high-level values (such as strings or
/// domain-specific types) without constructing HTTP responses manually.
///
/// # Example
///
/// ```ignore
/// async fn handler(request: Request, _: ()) -> Result<String, ()> {
///     "Hello, world!".to_string()
/// }
/// ```
pub trait IntoResponse {
    /// Converts `self` into an HTTP response.
    fn into_response(self) -> Response;
}

/// Identity implementation for [`Response`].
///
/// This allows handlers to return responses directly.
impl IntoResponse for Response {
    fn into_response(self) -> Response {
        self
    }
}

/// Converts a [`String`] into a plain-text HTTP response.
///
/// The string is used as the response body with the default body type.
impl IntoResponse for String {
    fn into_response(self) -> Response {
        Response::new(Full::new(Bytes::from(self)))
    }
}