aro-core 1.0.0

Core domain layer for the Aro web framework
Documentation
//! Route metadata types for the Aro framework.

/// HTTP methods supported by route attributes.
#[doc(hidden)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Method {
    Get,
    Post,
    Put,
    Delete,
    Patch,
}

impl Method {
    /// Returns the method name as an uppercase string.
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::Get => "GET",
            Self::Post => "POST",
            Self::Put => "PUT",
            Self::Delete => "DELETE",
            Self::Patch => "PATCH",
        }
    }
}

/// Route metadata emitted by the HTTP method attribute macros.
///
/// Each `#[get("/path")]`, `#[post("/path")]`, etc. attribute stores
/// this metadata as a hidden constant on the annotated function.
///
/// Fields are `pub` because route macros in user crates construct struct
/// literals; they are macro-internal and not part of the public API surface.
#[doc(hidden)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct RouteDef {
    pub method: Method,
    pub path: &'static str,
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn method_as_str_get() {
        assert_eq!(Method::Get.as_str(), "GET");
    }

    #[test]
    fn method_as_str_post() {
        assert_eq!(Method::Post.as_str(), "POST");
    }

    #[test]
    fn method_as_str_put() {
        assert_eq!(Method::Put.as_str(), "PUT");
    }

    #[test]
    fn method_as_str_patch() {
        assert_eq!(Method::Patch.as_str(), "PATCH");
    }

    #[test]
    fn method_as_str_delete() {
        assert_eq!(Method::Delete.as_str(), "DELETE");
    }

    #[test]
    fn route_def_construction_and_field_access() {
        let route = RouteDef {
            method: Method::Get,
            path: "/users",
        };
        assert_eq!(route.method, Method::Get);
        assert_eq!(route.path, "/users");
    }

    #[test]
    fn route_def_equality() {
        let a = RouteDef {
            method: Method::Post,
            path: "/items",
        };
        let b = RouteDef {
            method: Method::Post,
            path: "/items",
        };
        assert_eq!(a, b);
    }
}