Skip to content

Commit

Permalink
Add Eq implementation for String (FuelLabs#5055)
Browse files Browse the repository at this point in the history
## Description

The `Eq` implementation seems to have been missing since moving the
`String` type from sway-libs to the standard library.

## Checklist

- [ ] I have linked to any relevant issues.
- [ ] I have commented my code, particularly in hard-to-understand
areas.
- [ ] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [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.

Co-authored-by: bitzoic <[email protected]>
  • Loading branch information
bitzoic and bitzoic authored Aug 30, 2023
1 parent 675d134 commit 2d10293
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions sway-lib-std/src/string.sw
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,12 @@ impl From<raw_slice> for String {
}
}

impl Eq for String {
fn eq(self, other: Self) -> bool {
self.bytes == other.bytes
}
}

// Tests

#[test]
Expand Down Expand Up @@ -479,3 +485,13 @@ fn string_test_with_capacity() {

assert(string.capacity() == 4);
}

#[test]
fn string_test_equal() {
let string1 = String::from_ascii_str("fuel");
let string2 = String::from_ascii_str("fuel");
let string3 = String::from_ascii_str("blazingly fast");

assert(string1 == string2);
assert(string1 != string3);
}

0 comments on commit 2d10293

Please sign in to comment.