-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy patherror.rs
More file actions
67 lines (56 loc) · 1.51 KB
/
Copy patherror.rs
File metadata and controls
67 lines (56 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//! Curve-related error helpers.
#[cfg(not(feature = "std"))]
use alloc::string::String;
use core::{error, fmt};
use crate::error::{ErrorSource, IntoErrorSource};
/// Common curve error type.
pub struct CurveError(ErrorSource);
impl CurveError {
/// Creates a curve error from a source error.
#[cfg(feature = "std")]
pub fn new<E>(error: E) -> Self
where
E: IntoErrorSource,
{
Self(error.into_error_source())
}
/// Creates a curve error from a source error.
#[cfg(not(feature = "std"))]
pub fn new<E>(error: E) -> Self
where
E: fmt::Display + fmt::Debug + Send + Sync + 'static,
{
let error = anyhow::Error::msg(error);
Self(error.into_error_source())
}
}
impl fmt::Debug for CurveError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Debug::fmt(&self.0, f)
}
}
impl fmt::Display for CurveError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(&self.0, f)
}
}
impl From<ErrorSource> for CurveError {
fn from(error: ErrorSource) -> Self {
Self(error)
}
}
impl From<String> for CurveError {
fn from(message: String) -> Self {
Self(ErrorSource::from(message))
}
}
impl From<&'static str> for CurveError {
fn from(message: &'static str) -> Self {
Self(ErrorSource::from(message))
}
}
impl error::Error for CurveError {
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
Some(self.0.as_error())
}
}