From 09099a5298f5b0d5267c033a90c8d970cd64ed26 Mon Sep 17 00:00:00 2001 From: Pyfisch Date: Sun, 19 Jul 2015 14:18:41 +0200 Subject: [PATCH] add docs, improve readme --- README.md | 7 +++++++ src/lib.rs | 54 +++++++++++++++++++++++++++++++++++++----------------- 2 files changed, 44 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 0f34382..58e8bac 100644 --- a/README.md +++ b/README.md @@ -3,3 +3,10 @@ [![Coverage Status](https://coveralls.io/repos/pyfisch/rust-charsets/badge.svg)](https://coveralls.io/r/pyfisch/rust-charsets) [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE) [![crates.io](http://meritbadge.herokuapp.com/rust-charsets)](https://crates.io/crates/rust-charsets) + +The crate provides an enum representing all charset names used in Media Types +and HTTP header values. The list can be found at [the IANA Character Sets +registry](http://www.iana.org/assignments/character-sets/character-sets.xhtml). + +Charset names can be parsed from string, formatted to string and compared. +Unregistered charsets are represented useing an `Unregistered` variant. diff --git a/src/lib.rs b/src/lib.rs index 485e111..8f92d1d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,12 +1,27 @@ +#![deny(missing_docs)] +#![cfg_attr(test, deny(warnings))] + +//! The crate provides an enum representing all charset names used in Media Types +//! and HTTP header values. The list can be found at [the IANA Character Sets +//! registry](http://www.iana.org/assignments/character-sets/character-sets.xhtml). +//! +//! Charset names can be parsed from string, formatted to string and compared. +//! Charset names can be parsed from string, formatted to string and compared. +//! Unregistered charsets are represented using an `Unregistered` variant. + use std::fmt::{self, Display}; use std::str::FromStr; use std::ascii::AsciiExt; use std::error::Error as ErrorTrait; -use self::Charset::*; +pub use self::Charset::*; +/// An error type used for this crate. +/// +/// It may be extended in the future to give more information. #[derive(Debug, Eq, PartialEq)] pub enum Error { + /// Parsing as as charset failed. Invalid } @@ -171,22 +186,27 @@ impl PartialEq for Charset { } } -#[test] -fn test_parse() { - assert_eq!(UsAscii,"us-ascii".parse().unwrap()); - assert_eq!(UsAscii,"US-Ascii".parse().unwrap()); - assert_eq!(UsAscii,"US-ASCII".parse().unwrap()); - assert_eq!(ShiftJis,"Shift-JIS".parse().unwrap()); - assert_eq!(Unregistered("ABCD".to_owned()),"abcd".parse().unwrap()); -} +#[cfg(test)] +mod tests { + use super::*; -#[test] -fn test_display() { - assert_eq!("US-ASCII", format!("{}", UsAscii)); - assert_eq!("ABCD", format!("{}", Unregistered("ABCD".to_owned()))); -} + #[test] + fn test_parse() { + assert_eq!(UsAscii,"us-ascii".parse().unwrap()); + assert_eq!(UsAscii,"US-Ascii".parse().unwrap()); + assert_eq!(UsAscii,"US-ASCII".parse().unwrap()); + assert_eq!(ShiftJis,"Shift-JIS".parse().unwrap()); + assert_eq!(Unregistered("ABCD".to_owned()),"abcd".parse().unwrap()); + } -#[test] -fn test_cmp() { - assert_eq!(Unregistered("foobar".to_owned()), Unregistered("FOOBAR".to_owned())); + #[test] + fn test_display() { + assert_eq!("US-ASCII", format!("{}", UsAscii)); + assert_eq!("ABCD", format!("{}", Unregistered("ABCD".to_owned()))); + } + + #[test] + fn test_cmp() { + assert_eq!(Unregistered("foobar".to_owned()), Unregistered("FOOBAR".to_owned())); + } }