add docs, improve readme

This commit is contained in:
Pyfisch 2015-07-19 14:18:41 +02:00
parent 456d59cf0c
commit 09099a5298
2 changed files with 44 additions and 17 deletions

View File

@ -3,3 +3,10 @@
[![Coverage Status](https://coveralls.io/repos/pyfisch/rust-charsets/badge.svg)](https://coveralls.io/r/pyfisch/rust-charsets) [![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) [![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) [![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.

View File

@ -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::fmt::{self, Display};
use std::str::FromStr; use std::str::FromStr;
use std::ascii::AsciiExt; use std::ascii::AsciiExt;
use std::error::Error as ErrorTrait; 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)] #[derive(Debug, Eq, PartialEq)]
pub enum Error { pub enum Error {
/// Parsing as as charset failed.
Invalid Invalid
} }
@ -171,22 +186,27 @@ impl PartialEq for Charset {
} }
} }
#[test] #[cfg(test)]
fn test_parse() { mod tests {
use super::*;
#[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!(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!(ShiftJis,"Shift-JIS".parse().unwrap());
assert_eq!(Unregistered("ABCD".to_owned()),"abcd".parse().unwrap()); assert_eq!(Unregistered("ABCD".to_owned()),"abcd".parse().unwrap());
} }
#[test] #[test]
fn test_display() { fn test_display() {
assert_eq!("US-ASCII", format!("{}", UsAscii)); assert_eq!("US-ASCII", format!("{}", UsAscii));
assert_eq!("ABCD", format!("{}", Unregistered("ABCD".to_owned()))); assert_eq!("ABCD", format!("{}", Unregistered("ABCD".to_owned())));
} }
#[test] #[test]
fn test_cmp() { fn test_cmp() {
assert_eq!(Unregistered("foobar".to_owned()), Unregistered("FOOBAR".to_owned())); assert_eq!(Unregistered("foobar".to_owned()), Unregistered("FOOBAR".to_owned()));
}
} }