CurveError

Enum CurveError 

Source
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 (see OperationErrorKind 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

Fields

§reason: &'static str

Static description of the point-related issue

§

OperationError(OperationErrorKind)

General operational error

Tuple Fields

§0: OperationErrorKind

The specific kind of operation failure

§

StdError

Standard error with additional context

Fields

§reason: String

Detailed explanation of the error

§

InterpolationError(String)

Error during curve interpolation

Tuple Fields

§0: String

Description of the interpolation issue

§

ConstructionError(String)

Error during curve or structure construction

Tuple Fields

§0: String

Details about the construction failure

§

AnalysisError(String)

Error during curve analysis operations

Tuple Fields

§0: String

Explanation of the analysis issue

§

MetricsError(String)

Error when calculating or processing curve metrics

Tuple Fields

§0: String

Description of the metrics-related issue

Implementations§

Source§

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.
Source

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 a NotSupported operation error.
  • 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.
Source

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 an InvalidParameters operation error.
  • 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

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for CurveError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for CurveError

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
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.

§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 a CurvesError variant.

§Returns

  • CurvesError::StdError: The custom error type with a detailed reason 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 the to_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§

fn from(err: Box<dyn Error>) -> Self

Converts to this type from the input type.
Source§

impl From<CurveError> for GraphError

Source§

fn from(err: CurveError) -> Self

Converts to this type from the input type.
Source§

impl From<CurveError> for InterpolationError

Source§

fn from(err: CurveError) -> Self

Converts to this type from the input type.
Source§

impl From<CurveError> for MetricsError

Source§

fn from(err: CurveError) -> Self

Converts to this type from the input type.
Source§

impl From<GraphError> for CurveError

Source§

fn from(err: GraphError) -> Self

Converts to this type from the input type.
Source§

impl From<GreeksError> for CurveError

Source§

fn from(err: GreeksError) -> Self

Converts to this type from the input type.
Source§

impl From<InterpolationError> for CurveError

Source§

fn from(err: InterpolationError) -> Self

Converts to this type from the input type.
Source§

impl From<MetricsError> for CurveError

Source§

fn from(err: MetricsError) -> Self

Converts to this type from the input type.
Source§

impl From<OptionsError> for CurveError

Source§

fn from(err: OptionsError) -> Self

Converts to this type from the input type.
Source§

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 the to_string representation of the PositionError, ensuring a human-readable explanation.
§Example Integration:
  1. If a PositionError is encountered during curve calculations, this implementation converts it into a CurvesError for consistent error handling within the curves module.
  2. 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

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more