/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ #[macro_use] extern crate typed_urls_derive; #[macro_use] extern crate serde_json; use typed_urls::TypedUrl; use std::collections::HashMap; #[derive(TypedUrl, Debug)] pub enum Url { #[routefmt = "/worlds"] Worlds, #[routefmt = "/worlds/{}"] World { world_key : String }, #[routefmt = "/worlds/{}/character/{}"] Character { world_key : String, character_key : String, }, #[routefmt = "/worlds/{}/map/{}/tile/{}/{}/{}"] Tile { world_key : String, map_key : String, x : i32, y : i32, z : i32, }, } #[test] fn to_string() { assert_eq!(Url::Worlds.to_string(), "/worlds"); assert_eq!(Url::World { world_key : "olympe".to_owned() }.to_string(), "/worlds/olympe"); } #[test] fn from_route() { let arg = HashMap::new(); assert_eq!(Url::from_route(&Route::Worlds, &arg).unwrap().to_string(), "/worlds"); let mut arg = HashMap::new(); arg.insert("world_key".to_owned(), json!("olympe")); assert_eq!(Url::from_route(&Route::World, &arg).unwrap().to_string(), "/worlds/olympe"); }