pub enum CurveError {
Point2DError {
reason: &'static str,
},
OperationError(OperationErrorKind),
StdError {
reason: String,
},
InterpolationError(String),
ConstructionError(String),
AnalysisError(String),
MetricsError(String),
}
Expand description
Represents different types of errors that can occur in the curves
module.
This enum categorizes errors that may be encountered when working with curve-related operations such as interpolation, construction, analysis, and other mathematical operations on curves and points.
§Variants
§Point2DError
Represents errors related to 2D point operations.
reason
- A static string explaining the specific point-related issue.
This variant is used for fundamental issues with points like invalid coordinates, missing values, or formatting problems.
§OperationError
Encapsulates general operational errors.
OperationErrorKind
- The specific kind of operation failure (seeOperationErrorKind
enum).
Used when an operation fails due to unsupported features or invalid parameters.
§StdError
Wraps standard errors with additional context.
reason
- A dynamic string providing detailed error information.
Suitable for general error cases where specialized variants don’t apply.
§InterpolationError
Indicates issues during the curve interpolation process.
String
- A human-readable explanation of the interpolation failure.
Used when problems occur during data point interpolation or curve generation.
§ConstructionError
Represents errors during the construction of curves or related structures.
String
- A description of the construction issue.
Applicable when curve initialization fails due to invalid inputs, unsupported configurations, or missing required parameters.
§AnalysisError
Captures errors related to curve analysis operations.
String
- A detailed explanation of the analysis failure.
Used for failures in analytical methods like curve fitting, differentiation, or other mathematical operations on curves.
§MetricsError
Represents errors when calculating or processing curve metrics.
String
- An explanation of the metrics-related issue.
Used when metric calculations fail due to invalid inputs or computational issues.
§Usage
This error type is designed to be used throughout the curves
module wherever
operations might fail. It provides structured error information to help diagnose
and handle various failure scenarios.
§Implementation Notes
The error variants are designed to provide useful context for debugging and error handling. Each variant includes specific information relevant to its error category.
§Examples
// Example of creating a construction error
use optionstratlib::error::CurveError;
let error = CurveError::ConstructionError("Insufficient points to construct curve".to_string());
// Example of creating a point error
let point_error = CurveError::Point2DError { reason: "Point coordinates out of bounds" };
Variants§
Point2DError
Error related to 2D point operations
OperationError(OperationErrorKind)
General operational error
Tuple Fields
0: OperationErrorKind
The specific kind of operation failure
StdError
Standard error with additional context
InterpolationError(String)
Error during curve interpolation
ConstructionError(String)
Error during curve or structure construction
AnalysisError(String)
Error during curve analysis operations
MetricsError(String)
Error when calculating or processing curve metrics
Implementations§
Source§impl CurveError
Provides helper methods for constructing specific variants of the CurvesError
type.
impl CurveError
Provides helper methods for constructing specific variants of the CurvesError
type.
These methods encapsulate common patterns of error creation, making it easier to consistently generate errors with the necessary context.
§Integration
- These methods simplify the process of creating meaningful error objects, improving readability
and maintainability of the code using the
CurvesError
type. - The constructed errors leverage the
OperationErrorKind
to ensure structured and detailed error categorization.
Sourcepub fn operation_not_supported(operation: &str, reason: &str) -> Self
pub fn operation_not_supported(operation: &str, reason: &str) -> Self
§operation_not_supported
Constructs a CurvesError::OperationError
with an OperationErrorKind::NotSupported
variant.
- Parameters:
operation
(&str
): The name of the operation that is not supported.reason
(&str
): A description of why the operation is not supported.
- Returns:
- A
CurvesError
containing aNotSupported
operation error.
- A
- Use Cases:
- Invoked when a requested operation is not compatible with the current context.
- For example, attempting an unsupported computation method on a specific curve type.
Sourcepub fn invalid_parameters(operation: &str, reason: &str) -> Self
pub fn invalid_parameters(operation: &str, reason: &str) -> Self
§invalid_parameters
Constructs a CurvesError::OperationError
with an OperationErrorKind::InvalidParameters
variant.
- Parameters:
operation
(&str
): The name of the operation that encountered invalid parameters.reason
(&str
): A description of why the parameters are invalid.
- Returns:
- A
CurvesError
containing anInvalidParameters
operation error.
- A
- Use Cases:
- Used when an operation fails due to issues with the provided input.
- For example, providing malformed or missing parameters for interpolation or curve construction.
Trait Implementations§
Source§impl Debug for CurveError
impl Debug for CurveError
Source§impl Display for CurveError
impl Display for CurveError
Source§impl Error for CurveError
impl Error for CurveError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
Source§impl From<Box<dyn Error>> for CurveError
Implements the From
trait to enable seamless conversion from a boxed dyn Error
into a CurvesError
. This is particularly useful for integrating standard error
handling mechanisms with the custom CurvesError
type.
impl From<Box<dyn Error>> for CurveError
Implements the From
trait to enable seamless conversion from a boxed dyn Error
into a CurvesError
. This is particularly useful for integrating standard error
handling mechanisms with the custom CurvesError
type.
§Behavior
When constructing a CurvesError
from a Box<dyn Error>
, the StdError
variant
is utilized. The Box<dyn Error>
is unwrapped, and its string representation
(via to_string
) is used to populate the reason
field of the StdError
variant.
§Parameters
err
: A boxed standard error (Box<dyn Error>
). Represents the error to be wrapped within aCurvesError
variant.
§Returns
CurvesError::StdError
: The custom error type with a detailedreason
string derived from the provided error.
§Usage
This implementation is commonly employed when you need to bridge standard Rust
errors with the specific error handling system provided by the curves
module.
It facilitates scenarios where standard error contexts need to be preserved
in a flexible, string-based reason
for debugging or logging purposes.
§Example Scenario
Instead of handling standard errors separately, you can propagate them as CurvesError
within the larger error system of the curves
module, ensuring consistent error
wrapping and management.
§Notes
- This implementation assumes that all input errors (
Box<dyn Error>
) are stringifiable using theto_string()
method. - This conversion is particularly useful for libraries integrating generalized errors (e.g., I/O errors, or third-party library errors) into a standardized error system.
§Module Context
This conversion is provided in the crate::error::curves
module, which defines
the CurvesError
enum encompassing multiple errors related to curve operations.
Source§impl From<CurveError> for GraphError
impl From<CurveError> for GraphError
Source§fn from(err: CurveError) -> Self
fn from(err: CurveError) -> Self
Source§impl From<CurveError> for InterpolationError
impl From<CurveError> for InterpolationError
Source§fn from(err: CurveError) -> Self
fn from(err: CurveError) -> Self
Source§impl From<CurveError> for MetricsError
impl From<CurveError> for MetricsError
Source§fn from(err: CurveError) -> Self
fn from(err: CurveError) -> Self
Source§impl From<GraphError> for CurveError
impl From<GraphError> for CurveError
Source§fn from(err: GraphError) -> Self
fn from(err: GraphError) -> Self
Source§impl From<GreeksError> for CurveError
impl From<GreeksError> for CurveError
Source§fn from(err: GreeksError) -> Self
fn from(err: GreeksError) -> Self
Source§impl From<InterpolationError> for CurveError
impl From<InterpolationError> for CurveError
Source§fn from(err: InterpolationError) -> Self
fn from(err: InterpolationError) -> Self
Source§impl From<MetricsError> for CurveError
impl From<MetricsError> for CurveError
Source§fn from(err: MetricsError) -> Self
fn from(err: MetricsError) -> Self
Source§impl From<OptionsError> for CurveError
impl From<OptionsError> for CurveError
Source§fn from(err: OptionsError) -> Self
fn from(err: OptionsError) -> Self
Source§impl From<PositionError> for CurveError
Converts a PositionError
into a CurvesError
by mapping it to an
OperationError
with the InvalidParameters
variant.
impl From<PositionError> for CurveError
Converts a PositionError
into a CurvesError
by mapping it to an
OperationError
with the InvalidParameters
variant.
This implementation ensures a smooth transition between error types
when a PositionError
is encountered within a context that operates
on the curves
module. The InvalidParameters
variant is used to
provide detailed information about the failed operation and the reason
for its failure.
§Details:
- The
operation
field is hardcoded as"Position"
to indicate the context of the error (i.e., relating to position management). - The
reason
field is derived from theto_string
representation of thePositionError
, ensuring a human-readable explanation.
§Example Integration:
- If a
PositionError
is encountered during curve calculations, this implementation converts it into aCurvesError
for consistent error handling within thecurves
module. - The generated
CurvesError
provides detailed diagnostic information about the reason for the failure, enabling effective debugging.
§Implementation Notes:
- This conversion leverages the
OperationErrorKind::InvalidParameters
variant to communicate that invalid parameters (or settings) were the root cause of failure. - Use this implementation to handle interoperability between error types in modular design contexts.
§Example Use Case:
This conversion is frequently used in scenarios where:
- A position-related error (e.g., from validation or limits) occurs during a curve operation.
- Such errors need to be mapped into the
CurvesError
domain to maintain consistent error handling across the library.
§Debugging:
The resulting CurvesError
will include contextual details, making it
straightforward to trace and debug the underlying issue.
Source§fn from(err: PositionError) -> Self
fn from(err: PositionError) -> Self
Auto Trait Implementations§
impl Freeze for CurveError
impl RefUnwindSafe for CurveError
impl Send for CurveError
impl Sync for CurveError
impl Unpin for CurveError
impl UnwindSafe for CurveError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.