Mercurial > core / rust/lib/obj/src/object/direction.rs
changeset 698: |
96958d3eb5b0 |
parent: |
c7165d93a9eb
|
author: |
Richard Westhaver <ellis@rwest.io> |
date: |
Fri, 04 Oct 2024 22:04:59 -0400 |
permissions: |
-rw-r--r-- |
description: |
fixes |
2 use crate::{Deserialize, Error, Serialize}; 4 #[derive(Debug, Default, Serialize, Deserialize)] 5 pub enum CardinalDirection { 13 impl FromStr for CardinalDirection { 16 fn from_str(s: &str) -> Result<CardinalDirection, Self::Err> { 18 "north" => Ok(CardinalDirection::North), 19 "south" => Ok(CardinalDirection::South), 20 "east" => Ok(CardinalDirection::East), 21 "west" => Ok(CardinalDirection::West), 22 _ => Err(Error::Message("not a CardinalDirection".to_string())), 27 impl From<CardinalDirection> for String { 28 fn from(d: CardinalDirection) -> Self { 30 CardinalDirection::North => "north".to_string(), 31 CardinalDirection::South => "south".to_string(), 32 CardinalDirection::East => "east".to_string(), 33 CardinalDirection::West => "west".to_string(), 38 #[derive(Debug, Default, Serialize, Deserialize)] 39 pub enum RelativeDirection { 47 impl FromStr for RelativeDirection { 50 fn from_str(s: &str) -> Result<RelativeDirection, Self::Err> { 52 "up" | "u" => Ok(RelativeDirection::Up), 53 "down" | "d" => Ok(RelativeDirection::Down), 54 "left" | "l" => Ok(RelativeDirection::Left), 55 "right" | "r" => Ok(RelativeDirection::Right), 56 _ => Err(Error::Message("not a RelativeDirection".to_string())), 61 impl From<RelativeDirection> for String { 62 fn from(d: RelativeDirection) -> Self { 64 RelativeDirection::Up => "up".to_string(), 65 RelativeDirection::Down => "down".to_string(), 66 RelativeDirection::Left => "left".to_string(), 67 RelativeDirection::Right => "right".to_string(), 72 #[derive(Eq, PartialEq, Clone, Debug, Hash, Copy, Serialize, Deserialize)] 73 pub enum EdgeDirection { 78 impl FromStr for EdgeDirection { 81 fn from_str(s: &str) -> Result<EdgeDirection, Self::Err> { 83 "outbound" => Ok(EdgeDirection::Outbound), 84 "inbound" => Ok(EdgeDirection::Inbound), 85 _ => Err(Error::Message("not an EdgeDirection".to_string())), 90 impl From<EdgeDirection> for String { 91 fn from(d: EdgeDirection) -> Self { 93 EdgeDirection::Outbound => "outbound".to_string(), 94 EdgeDirection::Inbound => "inbound".to_string(),