FuelLabs / FuelLabs/sway

Consider replacing `From<raw_slice> for Vec<T>` with `TryFrom<raw_slice> for Vec<T>`

Open
#7,679 0 comments 0 reactions 0 assignees View on GitHub
lib: std
Dominant language
Rust
Stars
61.4k
Forks
5.4k
Avg merge
3h 33m
Merged PRs (30d)
4

Description

If the size of the slice in bytes is not a multiple of `__size_of::` this very likely represents a bug in the program. Currently, we just take the maximum number of elements of `T` that fit into the slice, leaving the trailing bytes and not reporting any potential issue.

Having `TryFrom` here would clearly indicate the size mismatch.

Similar issue we have in `raw_slice::len::()` where the length is actually the maximum number of elements of `T` that fit into the slice. This can also be a source of bugs.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by locating the From for Vec implementation and raw_slice::len() mentioned in the issue. Review how these APIs handle slices whose byte length is not divisible by the element size, then verify that mismatches are reported and the length behavior is addressed consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.