add docs, improve readme
This commit is contained in:
parent
456d59cf0c
commit
09099a5298
@ -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.
|
||||
|
54
src/lib.rs
54
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()));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user