1
0
mirror of https://gitlab.com/xmpp-rs/xmpp-rs.git synced 2024-06-11 18:54:03 +02:00

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;
/// Errors this library can produce.
#[derive(Debug)]
#[derive(Debug, PartialEq, Eq)]
pub enum Error {
/// An error produced by one of the ICU functions.
Icu(String),
@ -24,22 +24,6 @@ pub enum Error {
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 {
pub(crate) fn from_icu_code(err: UErrorCode) -> Error {
let ptr = unsafe { icu_error_code_to_name(err) };