diff --git a/src/data_centers.rs b/src/data_centers.rs index cf2b643..f67f2da 100644 --- a/src/data_centers.rs +++ b/src/data_centers.rs @@ -1,3 +1,5 @@ +//! Data center types + use errors::UnknownVariant; use std::fmt::{Display, Formatter, Result as FmtResult}; diff --git a/src/errors.rs b/src/errors.rs index 4d6a8a9..1868e06 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -1,7 +1,21 @@ +//! Error types (non-FFXIV) + use std::fmt::{Display, Formatter, Result as FmtResult}; +/// An error representing an unknown variant of any `enum`. +/// +/// `(enum name, unknown variant)`, e.g. `("DataCenter", "my invalid input")` +/// +/// This is generally encountered when using [`FromStr`] on any `enum` in this crate. +/// +/// [`FromStr`]: ::std::str::FromStr #[derive(Debug)] -pub struct UnknownVariant(pub &'static str, pub String); +pub struct UnknownVariant( + /// The `enum` name (e.g. `"DataCenter"`) + pub &'static str, + /// The unknown variant given + pub String +); impl Display for UnknownVariant { fn fmt(&self, f: &mut Formatter) -> FmtResult { diff --git a/src/lib.rs b/src/lib.rs index aacfd66..ec3393c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,5 @@ +//! Types for use in FFXIV-related projects. + pub mod data_centers; pub mod errors; pub mod jobs; diff --git a/src/roles.rs b/src/roles.rs index c85bc0b..70ded79 100644 --- a/src/roles.rs +++ b/src/roles.rs @@ -1,8 +1,13 @@ +//! Job role types + use errors::UnknownVariant; use std::fmt::{Display, Formatter, Result as FmtResult}; use std::str::FromStr; +/// The roles available in the game. +/// +/// Each [Job] has a role attached to it. #[derive(Debug, Clone, Copy)] pub enum Role { Dps, diff --git a/src/worlds.rs b/src/worlds.rs index 1e07c64..1b352c6 100644 --- a/src/worlds.rs +++ b/src/worlds.rs @@ -1,3 +1,5 @@ +//! World types + use data_centers::DataCenter; use errors::UnknownVariant; @@ -6,7 +8,7 @@ use std::str::FromStr; /// The worlds, sometimes called servers, in the game. /// -/// Each [Data Center] has multiple worlds attached to it. +/// Each [`DataCenter`] has multiple worlds attached to it. #[derive(Debug, Clone, Copy)] pub enum World { // Aether @@ -169,6 +171,7 @@ impl World { World::Ultros, ]; + /// Returns the string variant of this world. pub fn as_str(&self) -> &'static str { match *self { World::Adamantoise => "Adamantoise", @@ -245,6 +248,7 @@ impl World { } } + /// Returns the [`DataCenter`] this world is on. pub fn data_center(&self) -> DataCenter { match *self { World::Adamantoise | @@ -325,6 +329,9 @@ impl World { impl FromStr for World { type Err = UnknownVariant; + /// Parses a string `s` to return a value of this type. + /// + /// This is case-insensitive. fn from_str(s: &str) -> Result { let world = match s.to_lowercase().as_str() { "adamantoise" => World::Adamantoise,