pub enum CurveError {
Point2DError {
reason: &'static str,
},
OperationError(OperationErrorKind),
RenderError {
backend: &'static str,
reason: String,
},
InterpolationError(String),
ConstructionError(String),
AnalysisError(String),
MetricsError(String),
Position(PositionError),
Options(OptionsError),
Greeks(GreeksError),
InterpolationOp(String),
Graph(Box<GraphError>),
}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 (seeOperationErrorKindenum).
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: OperationErrorKindThe specific kind of operation failure
RenderError
A rendering operation failed. Preserves the backend discriminator so
callers can distinguish plotters output paths from other backends
without resorting to a String catch-all.
Fields
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
Position(PositionError)
Error from position operations
Options(OptionsError)
Error from options operations
Greeks(GreeksError)
Error from Greeks calculations
InterpolationOp(String)
Error from interpolation operations
Graph(Box<GraphError>)
Error from graph operations
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
CurvesErrortype. - The constructed errors leverage the
OperationErrorKindto 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
CurvesErrorcontaining aNotSupportedoperation 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
CurvesErrorcontaining anInvalidParametersoperation 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
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
use the Display impl or to_string()
Source§impl From<CurveError> for ChainError
impl From<CurveError> for ChainError
Source§fn from(err: CurveError) -> Self
fn from(err: CurveError) -> Self
Source§impl From<CurveError> for Error
impl From<CurveError> for Error
Source§fn from(source: CurveError) -> Self
fn from(source: CurveError) -> Self
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(source: CurveError) -> Self
fn from(source: 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(source: GreeksError) -> Self
fn from(source: 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
Converts a PositionError into a CurvesError by mapping it to an
OperationError with the InvalidParameters variant.
impl From<MetricsError> 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
operationfield is hardcoded as"Position"to indicate the context of the error (i.e., relating to position management). - The
reasonfield is derived from theto_stringrepresentation of thePositionError, ensuring a human-readable explanation.
§Example Integration:
- If a
PositionErroris encountered during curve calculations, this implementation converts it into aCurvesErrorfor consistent error handling within thecurvesmodule. - The generated
CurvesErrorprovides detailed diagnostic information about the reason for the failure, enabling effective debugging.
§Implementation Notes:
- This conversion leverages the
OperationErrorKind::InvalidParametersvariant 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
CurvesErrordomain 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: MetricsError) -> Self
fn from(err: MetricsError) -> Self
Source§impl From<OptionsError> for CurveError
impl From<OptionsError> for CurveError
Source§fn from(source: OptionsError) -> Self
fn from(source: OptionsError) -> Self
Source§impl From<PositionError> for CurveError
impl From<PositionError> for CurveError
Source§fn from(source: PositionError) -> Self
fn from(source: 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 UnsafeUnpin 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.