1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
use actix_web::HttpRequest; use rustimate_service::ctx::Router; use rustimate_core::{Error, Result}; pub(crate) struct RequestRouter { req: HttpRequest } impl RequestRouter { pub(crate) fn new(req: HttpRequest) -> RequestRouter { RequestRouter { req } } } impl Router for RequestRouter { fn route(&self, path: &str, args: &[&str]) -> Result<String> { self .req .url_for(path, args) .map(|x| x.path().into()) .map_err(|_| Error::from(format!("Unable to find route for [{}]", path))) } }