You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## Description
There exists no `resize()` functionality for `Vec` and `Bytes`. This has
been implemented in this PR and mimics Rust's behavior.
## Checklist
- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [x] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [x] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [x] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
Copy file name to clipboardexpand all lines: sway-lib-std/src/bytes.sw
+55
Original file line number
Diff line number
Diff line change
@@ -816,6 +816,61 @@ impl Bytes {
816
816
817
817
spliced
818
818
}
819
+
820
+
/// Resizes the `Bytes` in-place so that `len` is equal to `new_len`.
821
+
///
822
+
/// # Additional Information
823
+
///
824
+
/// If `new_len` is greater than `len`, the `Bytes` is extended by the difference, with each additional slot filled with `value`. If `new_len` is less than `len`, the `Bytes` is simply truncated.
825
+
///
826
+
/// # Arguments
827
+
///
828
+
/// * `new_len`: [u64] - The new length of the `Bytes`.
829
+
/// * `value`: [u8] - The value to fill the new length.
Copy file name to clipboardexpand all lines: sway-lib-std/src/vec.sw
+55
Original file line number
Diff line number
Diff line change
@@ -698,6 +698,61 @@ impl<T> Vec<T> {
698
698
pubfnptr(self) ->raw_ptr {
699
699
self.buf.ptr()
700
700
}
701
+
702
+
/// Resizes the `Vec` in-place so that `len` is equal to `new_len`.
703
+
///
704
+
/// # Additional Information
705
+
///
706
+
/// If `new_len` is greater than `len`, the `Vec` is extended by the difference, with each additional slot filled with `value`. If `new_len` is less than `len`, the `Vec` is simply truncated.
707
+
///
708
+
/// # Arguments
709
+
///
710
+
/// * `new_len`: [u64] - The new length of the `Vec`.
711
+
/// * `value`: [T] - The value to fill the new length.
0 commit comments