Nullus157 / bs58-rs

Another Rust Base58 codec implementation
Apache License 2.0
75 stars 24 forks source link

Return length during const decoding #120

Open joncinque opened 3 months ago

joncinque commented 3 months ago

Problem

The current API for const-decoding only returns the resulting array, which makes it impossible for a user to check that the input had the correct length. This is an important use-case for things like wallet addresses, where people often make typos by forgetting to paste a character.

Proposed changes

Since there's no onto() API available in const contexts, this PR introduces a breaking change by having into_array_const also return the length decoded. I couldn't come up with a way to eliminate the breaking change without also introducing a lot of copied code, since we can't call Result::map in a const context.

I apologize for coming back with another change so soon, but I only discovered the issue when playing around with the API more recently. Let me know what you think!