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.
|
||||
|
22
src/lib.rs
22
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,6 +186,10 @@ impl PartialEq for Charset {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_parse() {
|
||||
assert_eq!(UsAscii,"us-ascii".parse().unwrap());
|
||||
@ -190,3 +209,4 @@ fn test_display() {
|
||||
fn test_cmp() {
|
||||
assert_eq!(Unregistered("foobar".to_owned()), Unregistered("FOOBAR".to_owned()));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user