Skip to content

Commit 72d7560

Browse files
authored
Remove thiserror dependency (#141)
Removing the `thiserror` dependency.
1 parent 8346d35 commit 72d7560

File tree

4 files changed

+77
-60
lines changed

4 files changed

+77
-60
lines changed

Cargo.lock

Lines changed: 0 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/openvino/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ exclude = ["/tests"]
1515
[dependencies]
1616
openvino-sys = { workspace = true }
1717
openvino-finder = { workspace = true }
18-
thiserror = "1.0"
1918

2019
[dev-dependencies]
2120
float-cmp = "0.9"

crates/openvino/src/error.rs

Lines changed: 75 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,28 @@
1-
use thiserror::Error;
1+
use std::error::Error;
2+
use std::fmt;
23

34
/// Enumerate errors returned by the OpenVINO implementation. See
45
/// [`OvStatusCode`](https://docs.openvino.ai/2023.3/api/c_cpp_api/group__ov__base__c__api.html#_CPPv411ov_status_e).
5-
// TODO This could be auto-generated (https://github.com/intel/openvino-rs/issues/20).
66
#[allow(missing_docs)]
7-
#[derive(Debug, Error, PartialEq, Eq)]
7+
#[derive(Debug, PartialEq, Eq)]
88
pub enum InferenceError {
9-
#[error("general error")]
109
GeneralError,
11-
#[error("not implemented")]
1210
NotImplemented,
13-
#[error("network not loaded")]
1411
NetworkNotLoaded,
15-
#[error("parameter mismatch")]
1612
ParameterMismatch,
17-
#[error("not found")]
1813
NotFound,
19-
#[error("out of bounds")]
2014
OutOfBounds,
21-
#[error("unexpected")]
2215
Unexpected,
23-
#[error("request busy")]
2416
RequestBusy,
25-
#[error("result not ready")]
2617
ResultNotReady,
27-
#[error("not allocated")]
2818
NotAllocated,
29-
#[error("infer not started")]
3019
InferNotStarted,
31-
#[error("network not read")]
3220
NetworkNotRead,
33-
#[error("infer cancelled")]
3421
InferCancelled,
35-
#[error("invalid c parameter")]
3622
InvalidCParam,
37-
#[error("unknown C error")]
3823
UnknownCError,
39-
#[error("not implemented C method")]
4024
NotImplementCMethod,
41-
#[error("unknown exception")]
4225
UnknownException,
43-
#[error("undefined error code: {0}")]
4426
Undefined(i32),
4527
}
4628

@@ -75,28 +57,85 @@ impl InferenceError {
7557
}
7658
}
7759

78-
/// Enumerate setup failures: in some cases, this library will call library-loading code that may
79-
/// fail in a different way (i.e., [`LoadingError`]) than the calls to the OpenVINO libraries (i.e.,
80-
/// [`InferenceError`]).
81-
#[allow(missing_docs)]
82-
#[derive(Debug, Error)]
83-
pub enum SetupError {
84-
#[error("inference error")]
85-
Inference(#[from] InferenceError),
86-
#[error("library loading error")]
87-
Loading(#[from] LoadingError),
60+
impl Error for InferenceError {}
61+
62+
impl fmt::Display for InferenceError {
63+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
64+
match self {
65+
Self::GeneralError => write!(f, "general error"),
66+
Self::NotImplemented => write!(f, "not implemented"),
67+
Self::NetworkNotLoaded => write!(f, "network not loaded"),
68+
Self::ParameterMismatch => write!(f, "parameter mismatch"),
69+
Self::NotFound => write!(f, "not found"),
70+
Self::OutOfBounds => write!(f, "out of bounds"),
71+
Self::Unexpected => write!(f, "unexpected"),
72+
Self::RequestBusy => write!(f, "request busy"),
73+
Self::ResultNotReady => write!(f, "result not ready"),
74+
Self::NotAllocated => write!(f, "not allocated"),
75+
Self::InferNotStarted => write!(f, "infer not started"),
76+
Self::NetworkNotRead => write!(f, "network not read"),
77+
Self::InferCancelled => write!(f, "infer cancelled"),
78+
Self::InvalidCParam => write!(f, "invalid C parameter"),
79+
Self::UnknownCError => write!(f, "unknown C error"),
80+
Self::NotImplementCMethod => write!(f, "not implemented C method"),
81+
Self::UnknownException => write!(f, "unknown exception"),
82+
Self::Undefined(code) => write!(f, "undefined error code: {code}"),
83+
}
84+
}
8885
}
8986

9087
/// Enumerate the ways that library loading can fail.
9188
#[allow(missing_docs)]
92-
#[derive(Debug, Error)]
89+
#[derive(Debug)]
9390
pub enum LoadingError {
94-
#[error("system failed to load shared libraries (see https://github.com/intel/openvino-rs/blob/main/crates/openvino-finder): {0}")]
9591
SystemFailure(String),
96-
#[error("cannot find path to shared libraries (see https://github.com/intel/openvino-rs/blob/main/crates/openvino-finder)")]
9792
CannotFindLibraryPath,
98-
#[error("cannot find path to XML plugin configuration (see https://github.com/intel/openvino-rs/blob/main/crates/openvino-finder)")]
9993
CannotFindPluginPath,
100-
#[error("unable to convert path to a UTF-8 string (see https://doc.rust-lang.org/std/path/struct.Path.html#method.to_str)")]
10194
CannotStringifyPath,
10295
}
96+
97+
impl Error for LoadingError {}
98+
99+
impl fmt::Display for LoadingError {
100+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
101+
match self {
102+
Self::SystemFailure(msg) => write!(f, "system failed to load shared libraries (see https://github.com/intel/openvino-rs/blob/main/crates/openvino-finder): {msg}"),
103+
Self::CannotFindLibraryPath => write!(f, "cannot find path to shared libraries (see https://github.com/intel/openvino-rs/blob/main/crates/openvino-finder)"),
104+
Self::CannotFindPluginPath => write!(f, "cannot find path to XML plugin configuration (see https://github.com/intel/openvino-rs/blob/main/crates/openvino-finder)"),
105+
Self::CannotStringifyPath => write!(f, "unable to convert path to a UTF-8 string (see https://doc.rust-lang.org/std/path/struct.Path.html#method.to_str)"),
106+
}
107+
}
108+
}
109+
110+
/// Enumerate setup failures: in some cases, this library will call library-loading code that may
111+
/// fail in a different way (i.e., [`LoadingError`]) than the calls to the OpenVINO libraries (i.e.,
112+
/// [`InferenceError`]).
113+
#[allow(missing_docs)]
114+
#[derive(Debug)]
115+
pub enum SetupError {
116+
Inference(InferenceError),
117+
Loading(LoadingError),
118+
}
119+
120+
impl Error for SetupError {}
121+
122+
impl fmt::Display for SetupError {
123+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
124+
match self {
125+
Self::Inference(error) => write!(f, "inference error: {error}"),
126+
Self::Loading(error) => write!(f, "library loading error: {error}"),
127+
}
128+
}
129+
}
130+
131+
impl From<InferenceError> for SetupError {
132+
fn from(error: InferenceError) -> Self {
133+
SetupError::Inference(error)
134+
}
135+
}
136+
137+
impl From<LoadingError> for SetupError {
138+
fn from(error: LoadingError) -> Self {
139+
SetupError::Loading(error)
140+
}
141+
}

crates/openvino/src/request.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,12 @@ impl InferRequest {
121121
try_unsafe!(ov_infer_request_cancel(self.ptr))
122122
}
123123

124-
/// Execute the inference request asyncroneously.
124+
/// Execute the inference request asynchronously.
125125
pub fn infer_async(&mut self) -> Result<()> {
126126
try_unsafe!(ov_infer_request_start_async(self.ptr))
127127
}
128128

129-
/// Wait for the result of the inference asyncroneous request.
129+
/// Wait for the result of the inference asynchronous request.
130130
pub fn wait(&mut self, timeout: i64) -> Result<()> {
131131
try_unsafe!(ov_infer_request_wait_for(self.ptr, timeout))
132132
}

0 commit comments

Comments
 (0)