Remove usage of `try_into().unwrap()` where feasible

Open
#89 0 comments 0 reactions 1 assignee View on GitHub

Maintainers usually reply within 1 day

@xoloki is already working on this.

Since Nov 21, 2024.

  • #91 by @xoloki — closed without merging

Assessment

This issue has not been assessed yet.

Description

Early versions of wsts used usize types anywhere that the code would deal with the size of memory. But this is problematic when sending data over the network, since usize is a platform dependent type.

So at some point we changed all public integer types to be fixed size, i.e. u32 or u64. This required sprinkling as usize casts where needed. However, @jferrant discovered that as usize casts will fail silently if the cast value is improperly sized.

As a result, we now call try_into().unwrap() to handle all casts between u32/u64 and usize. The logic was that while these can fail, they are extremely unlikely to do so, and if they do it's likely a result of a misconfiguration that should be noticed and fixed.

However, since this is library code, it is bad form to ever panic when an error could be returned instead. So this issue will track work to remove these unwrap calls whenever feasible.

Dominant language
Rust
Stars
34
Forks
19
Avg merge
9h 19m
Merged PRs (30d)
12

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from xoloki/wsts

All issues in xoloki/wsts

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.