summaryrefslogtreecommitdiffstats
path: root/third_party/rust/autocfg/src/error.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
commit0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch)
treea31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /third_party/rust/autocfg/src/error.rs
parentInitial commit. (diff)
downloadfirefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz
firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/autocfg/src/error.rs')
-rw-r--r--third_party/rust/autocfg/src/error.rs69
1 files changed, 69 insertions, 0 deletions
diff --git a/third_party/rust/autocfg/src/error.rs b/third_party/rust/autocfg/src/error.rs
new file mode 100644
index 0000000000..4624835451
--- /dev/null
+++ b/third_party/rust/autocfg/src/error.rs
@@ -0,0 +1,69 @@
+use std::error;
+use std::fmt;
+use std::io;
+use std::num;
+use std::str;
+
+/// A common error type for the `autocfg` crate.
+#[derive(Debug)]
+pub struct Error {
+ kind: ErrorKind,
+}
+
+impl error::Error for Error {
+ fn description(&self) -> &str {
+ "AutoCfg error"
+ }
+
+ fn cause(&self) -> Option<&error::Error> {
+ match self.kind {
+ ErrorKind::Io(ref e) => Some(e),
+ ErrorKind::Num(ref e) => Some(e),
+ ErrorKind::Utf8(ref e) => Some(e),
+ ErrorKind::Other(_) => None,
+ }
+ }
+}
+
+impl fmt::Display for Error {
+ fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
+ match self.kind {
+ ErrorKind::Io(ref e) => e.fmt(f),
+ ErrorKind::Num(ref e) => e.fmt(f),
+ ErrorKind::Utf8(ref e) => e.fmt(f),
+ ErrorKind::Other(s) => s.fmt(f),
+ }
+ }
+}
+
+#[derive(Debug)]
+enum ErrorKind {
+ Io(io::Error),
+ Num(num::ParseIntError),
+ Utf8(str::Utf8Error),
+ Other(&'static str),
+}
+
+pub fn from_io(e: io::Error) -> Error {
+ Error {
+ kind: ErrorKind::Io(e),
+ }
+}
+
+pub fn from_num(e: num::ParseIntError) -> Error {
+ Error {
+ kind: ErrorKind::Num(e),
+ }
+}
+
+pub fn from_utf8(e: str::Utf8Error) -> Error {
+ Error {
+ kind: ErrorKind::Utf8(e),
+ }
+}
+
+pub fn from_str(s: &'static str) -> Error {
+ Error {
+ kind: ErrorKind::Other(s),
+ }
+}