10000 Add common impls for Error type · rust-osdev/ucs2-rs@ad816f4 · GitHub
[go: up one dir, main page]

Skip to content

Commit ad816f4

Browse files
nicholasbishopGabrielMajeri
authored andcommitted
Add common impls for Error type
Derive `Eq`, `PartialEq`, `Ord`, `PartialOrd`, and `Hash`. Also add a `Display` impl.
1 parent 346a065 commit ad816f4

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/lib.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,28 @@
55
#![deny(clippy::all)]
66

77
use bit_field::BitField;
8+
use core::fmt::{self, Display, Formatter};
89

910
/// Possible errors returned by the API.
10-
#[derive(Debug, Copy, Clone)]
11+
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1112
pub enum Error {
1213
/// Not enough space left in the output buffer.
1314
BufferOverflow,
1415
/// Input contained a character which cannot be represented in UCS-2.
1516
MultiByte,
1617
}
1718

19+
impl Display for Error {
20+
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
21+
match self {
22+
Self::BufferOverflow => f.write_str("output buffer is too small"),
23+
Self::MultiByte => {
24+
f.write_str("input contains a character which cannot be represented in UCS-2")
25+
}
26+
}
27+
}
28+
}
29+
1830
type Result<T> = core::result::Result<T, Error>;
1931

2032
/// Encodes an input UTF-8 string into a UCS-2 string.

0 commit comments

Comments
 (0)
0