feather_runtime/runtime/service.rs
1use crate::http::{Request, Response};
2use may::net::TcpStream;
3use std::{io, sync::Arc};
4
5/// The outcome of the application's request handling.
6pub enum ServiceResult {
7 /// A standard HTTP response. The Connection Handler will serialize and write this.
8 Response(Response),
9 /// The Service has taken ownership of the `TcpStream` (e.g., for WebSockets).
10 /// The Connection Handler must terminate its loop immediately.
11 Consumed,
12}
13
14/// The trait representing the user's core application logic.
15pub trait Service: Send + Sync + 'static {
16 /// Handles an incoming request, receiving the Request and the underlying stream.
17 /// The stream is passed as an `Option` to allow the service to consume it for upgrades.
18 fn handle(&self, req: Request, stream: Option<TcpStream>) -> io::Result<ServiceResult>;
19}
20
21pub type ArcService = Arc<dyn Service>;