-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merge main into workflow dev branch #14
Open
StrongFennecs
wants to merge
11
commits into
release-workflow
Choose a base branch
from
main
base: release-workflow
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* Use `fs::read` instead of manual implementation * Remove unneeded `File::try_clone` Immutable references to `File` can also be written to. * Remove unneeded `Cursor` References to `&[u8]` implement the needed `Read` and `Write` traits. * Use iterator methods to prepare dimble fields * Remove unneeded variables and types * Avoid creating Strings for two ASCII characters * Decode directly to desired type instead of going through `Value` * Reduce code duplication for converting integers * Coalesce panic and print statements * Use Iterator methods to build a new vector * Remove unneeded variable * Avoid checking the type twice * Use `unwrap_or_else` instead of manual matching * Extract duplicated calls to `set_item` * Simplify header length and data parsing * Use the header length constant in more places Since we use it as a `usize` some places, and a `u64` others, I changed the base type to a `u8`, which is large enough to represent the 8 bytes needed. This allows us to losslessly convert to a those two larger types. * Merge import statements * Demonstrate one way to create Rust errors and integrate with Python While it's possible to create your error types by hand, I like to use my library [SNAFU][snafu] to help with some of the boilerplate. There are other popular libraries such as `thiserror` or `anyhow` as well. I demonstrate a few facets of the crate here: 1. Creating opaque errors that do not expose internal details. Here, `ir_to_dimble::Error` wraps `ir_to_dimble::InnerError` and hides details except for the causal chain and error text. This is good for public APIs where you should be mindful of semver concerns. 2. Localized errors that compose into larger ones. `ir_to_dimble::SerialiseFieldsError` only deals with the ways that `serialise_dimble_fields` can fail and helps you avoid repetition and keep the scope a little tighter. I also followed PyO3's example and implemented a conversion from the Rust error to a `PyErr`, going through the existing `DimbleError`. This is a very basic implementation; a better one would expose the causal chain as a Python exception chain and potentially even have a traceback including Rust code. [snafu]: https://docs.rs/snafu/ * Remove unneeded ownership * Remove unneeded explicit types * DRY up repeated unwraps * DRY up repeated code
* changed format of README * fixed formatting readme --------- Co-authored-by: wallarug <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.