icu: Derive PartialEq and Eq

Also fixes a TODO about making comparisons better.
This commit is contained in:
Emmanuel Gil Peyrot 2022-09-20 19:13:55 +02:00
parent 4bfd85556d
commit e85b4260bd

View file

@ -6,7 +6,7 @@ use crate::bindings::{icu_error_code_to_name, UErrorCode};
use std::ffi::CStr; use std::ffi::CStr;
/// Errors this library can produce. /// Errors this library can produce.
#[derive(Debug)] #[derive(Debug, PartialEq, Eq)]
pub enum Error { pub enum Error {
/// An error produced by one of the ICU functions. /// An error produced by one of the ICU functions.
Icu(String), Icu(String),
@ -24,22 +24,6 @@ pub enum Error {
TooLong, TooLong,
} }
impl PartialEq for Error {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(Error::Icu(s1), Error::Icu(s2)) => s1 == s2,
(Error::Idna(s1), Error::Idna(s2)) => s1 == s2,
// TODO: compare by something here?
(Error::Utf8(_s1), Error::Utf8(_s2)) => true,
(Error::Utf16(_s1), Error::Utf16(_s2)) => true,
(Error::TooLong, Error::TooLong) => true,
_ => false,
}
}
}
impl Eq for Error {}
impl Error { impl Error {
pub(crate) fn from_icu_code(err: UErrorCode) -> Error { pub(crate) fn from_icu_code(err: UErrorCode) -> Error {
let ptr = unsafe { icu_error_code_to_name(err) }; let ptr = unsafe { icu_error_code_to_name(err) };