docs: add more

This commit is contained in:
Anna 2018-03-29 13:20:26 -04:00
parent 1d408d443b
commit 8f7de9824b
5 changed files with 32 additions and 2 deletions

View File

@ -1,3 +1,5 @@
//! Data center types
use errors::UnknownVariant;
use std::fmt::{Display, Formatter, Result as FmtResult};

View File

@ -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 {

View File

@ -1,3 +1,5 @@
//! Types for use in FFXIV-related projects.
pub mod data_centers;
pub mod errors;
pub mod jobs;

View File

@ -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,

View File

@ -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<Self, Self::Err> {
let world = match s.to_lowercase().as_str() {
"adamantoise" => World::Adamantoise,