an http based roguelike rpg about jelqing
Blame: src/game/outcome.rs
782069860236 | atagen | 2026-10-10 12:44 UTC | 1 | use axum::http::{HeaderName, StatusCode}; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 2 | use serde_json::Value; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 3 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 4 | pub enum Payload { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 5 | Empty, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 6 | Json(Value), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 7 | Raw(&'static str, Vec<u8>), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 8 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 9 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 10 | /// A successful result of a game action, before it becomes an HTTP response. |
782069860236 | atagen | 2026-10-10 12:44 UTC | 11 | pub struct Outcome { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 12 | pub status: StatusCode, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 13 | pub payload: Payload, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 14 | pub headers: Vec<(HeaderName, String)>, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 15 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 16 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 17 | impl Outcome { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 18 | pub fn empty(status: StatusCode) -> Self { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 19 | Self { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 20 | status, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 21 | payload: Payload::Empty, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 22 | headers: Vec::new(), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 23 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 24 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 25 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 26 | pub fn json(status: StatusCode, body: Value) -> Self { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 27 | Self { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 28 | payload: Payload::Json(body), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 29 | ..Self::empty(status) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 30 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 31 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 32 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 33 | pub fn raw(status: StatusCode, content_type: &'static str, body: impl Into<Vec<u8>>) -> Self { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 34 | Self { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 35 | payload: Payload::Raw(content_type, body.into()), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 36 | ..Self::empty(status) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 37 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 38 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 39 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 40 | pub fn header(mut self, name: HeaderName, value: impl Into<String>) -> Self { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 41 | self.headers.push((name, value.into())); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 42 | self |
782069860236 | atagen | 2026-10-10 12:44 UTC | 43 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 44 | } |