Skip to content
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

Let append_repeated_bytes and append_repeated_string take generic elements #17

Merged
merged 2 commits into from
Jan 20, 2024

Conversation

webmaster128
Copy link
Contributor

For #16

Not sure if this is the nicest approach. Lots is new type annotations necessary (at least in test code).

Copy link

@Buckram123 Buckram123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it, pretty sure it's mostly tests that would be impacted by specifying type, and it's still easier to put than convert Vec<T> into &[&T]

Left few suggestions, where it's possible to avoid type annotation, not sure if it's better tho 👀

src/anybuf.rs Outdated Show resolved Hide resolved
}

#[test]
fn append_repeated_bytes_works() {
// echo "id: \"bytess\"; bytess: [\"\", \"a\", \"bcde\"]" | protoc --encode=Collection *.proto | xxd -p -c 9999
let data = Anybuf::new()
.append_string(1, "bytess")
.append_repeated_bytes(10, &[b"", b"a", b"bcde"]);
.append_repeated_bytes::<&[u8]>(10, &[b"", b"a", b"bcde"]);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String slices could also be converted to bytes

Suggested change
.append_repeated_bytes::<&[u8]>(10, &[b"", b"a", b"bcde"]);
.append_repeated_bytes(10, &["", "a", "bcde"]);

/// vec![1u8; 10],
/// vec![2u8; 10],
/// vec![3u8; 10],
/// ];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nice thing about this example is that it also works the same way for Vec<cosmwasm_std::Binary> and Vec<cosmwasm_std::HexBinary>

@webmaster128 webmaster128 merged commit b625012 into main Jan 20, 2024
1 check passed
@webmaster128 webmaster128 deleted the impl-AsRef branch January 20, 2024 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants