Remove error type.

This commit is contained in:
Pyfisch 2016-09-01 12:01:33 +02:00
parent 21f1730f9d
commit 9b164fdbfb
2 changed files with 3 additions and 28 deletions

View File

@ -1,6 +1,6 @@
[package] [package]
name = "charsets" name = "charsets"
version = "0.1.1" version = "0.2.0"
authors = ["Pyfisch <pyfisch@gmail.com>"] authors = ["Pyfisch <pyfisch@gmail.com>"]
description = "An enum representing all charset names commonly used." description = "An enum representing all charset names commonly used."
readme = "README.md" readme = "README.md"

View File

@ -12,34 +12,9 @@
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;
pub 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,
}
impl ErrorTrait for Error {
fn description(&self) -> &str {
return "The given charset is invalid";
}
}
impl Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(self.description())
}
}
/// Result type used for this library.
pub type Result<T> = ::std::result::Result<T, Error>;
/// A Mime charset. /// A Mime charset.
/// ///
/// The string representation is normalised to upper case. /// The string representation is normalised to upper case.
@ -146,8 +121,8 @@ impl Display for Charset {
} }
impl FromStr for Charset { impl FromStr for Charset {
type Err = ::Error; type Err = ();
fn from_str(s: &str) -> ::Result<Charset> { fn from_str(s: &str) -> Result<Charset, ()> {
Ok(MAPPING.iter() Ok(MAPPING.iter()
.find(|&&(_, ref name)| name.eq_ignore_ascii_case(s)) .find(|&&(_, ref name)| name.eq_ignore_ascii_case(s))
.map(|&(ref variant, _)| variant.to_owned()) .map(|&(ref variant, _)| variant.to_owned())