Skip to content

Commit

Permalink
Add trait bound for std::error::Error (#17)
Browse files Browse the repository at this point in the history
<!-- Reference any GitHub issues resolved by this PR -->

Closes #

## Introduced changes

<!-- A brief description of the changes -->

- Add trait bound for std::error::Error so somebody can use `?` operator

## Checklist

<!-- Make sure all of these are complete -->

- [ ] Linked relevant issue
- [ ] Updated relevant documentation
- [ ] Added relevant tests
- [x] Performed self-review of the code
- [ ] Added changes to `CHANGELOG.md`
  • Loading branch information
ksew1 authored Oct 3, 2024
1 parent 3af55e5 commit cb3a04b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
21 changes: 14 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ edition = "2021"
cairo-lang-sierra-to-casm = "2.8.2"
cairo-lang-sierra = "2.8.2"
camino = { version = "1.1.9", features = ["serde1"] }
thiserror = "1.0.64"
derive_more = { version = "1.0.0", features = ["add", "add_assign", "mul", "mul_assign"] }
serde = { version = "1.0.195", features = ["derive"] }
serde_json = "1.0.128"
Expand Down
1 change: 1 addition & 0 deletions crates/cairo-annotations/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition.workspace = true
cairo-lang-sierra-to-casm.workspace = true
cairo-lang-sierra.workspace = true
camino.workspace = true
thiserror.workspace = true
derive_more.workspace = true
serde.workspace = true
serde_json.workspace = true
Expand Down
14 changes: 9 additions & 5 deletions crates/cairo-annotations/src/annotations/traits.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use cairo_lang_sierra::debug_info::DebugInfo;
use serde::de::DeserializeOwned;
use thiserror::Error;

pub trait TryFromDebugInfo: Sized {
type Error;
type Error: std::error::Error;

/// Attempt to create an instance of the implementing type from the provided sierra `DebugInfo`.
/// # Errors
Expand All @@ -12,12 +13,15 @@ pub trait TryFromDebugInfo: Sized {
}

/// Enum representing the possible errors that can occur when trying to create an annotation from sierra debug information.
#[derive(Debug)]
#[derive(Debug, Error)]
pub enum AnnotationsError {
/// Error indicating that the namespace is missing from the annotations. Contains the missing namespace.
/// Error indicating that the namespace is missing from the annotations.
#[error("Missing namespace: {0}")]
MissingNamespace(String),
/// Error indicating that the deserialization of the annotation failed. Contains the deserialization error.
DeserializationError(serde_json::Error),

/// Error indicating that the deserialization of the annotation failed.
#[error("Deserialization error: {0}")]
DeserializationError(#[from] serde_json::Error),
}

pub(crate) trait Namespace {
Expand Down

0 comments on commit cb3a04b

Please sign in to comment.