Comments (6)
Agreed. Should be a pretty easy change and I think worth a breaking release.
from bs58-rs.
Would you expect the same when decoding into a &mut Vec<u8>
(vs &mut [u8]
)?
#[test]
fn append() {
let mut buf = b"hello world".to_owned();
bs58::decode("a").into(&mut buf).unwrap();
assert_eq!(b"hello world!", buf.as_ref());
}
#[test]
fn no_append() {
let mut buf = b"hello world".to_owned();
bs58::decode("a").into(buf.as_mut()).unwrap();
assert_eq!(b"!ello world", buf.as_ref());
}
from bs58-rs.
For Vec<u8>
, I'd expect expect the same behavior as for String -- append the end.
For &mut [u8]
, I'd expect the same behavior as char::encode_utf8
-- overwrite the prefix, return the str
slice of the data actually written.
from bs58-rs.
Returning an &str
would require checking/asserting utf-8 validity at that point, if you're doing more ASCII-only processing on the buffer (or never actually asserting it is a string) then you might want to delay that.
from bs58-rs.
Hm, I think base58 guarantees that the encoded result is utf8, so no additional validation is necessary? If this assumption is correct, that returning &mut str
allows the calling code to avoid utf8-validation and bounds checking. In any case, returning just usize
signifying the amount of bytes written would be fine as well. Maybe retuning usize is even better: I wager that the main benefit for char's return type is not actaully eliding the check, but just basic conveniecne for cases where you'd want to encode char to a local [u8; 4]
, and then do something with the resulting string.
from bs58-rs.
Yeah, it wouldn't need validating since the API guarantees it's ASCII, but I want to minimize the unsafe code here (currently the only unsafe code used is the bare minimum necessary to actually work with &mut str
).
from bs58-rs.
Related Issues (20)
- crates release? HOT 4
- Enhance Large Input Decoding Performance HOT 5
- Nightly build failed
- Nightly build failed
- Nightly build failed
- Nightly build failed
- Mark error variants as nonexhaustive HOT 2
- Error type stutter
- Support encoding to a fixed-size buffer HOT 3
- Doesn't decode 32 bytes of 0x00
- encode() is O(n^2) HOT 1
- Release 0.2.3? HOT 1
- When do you plan to release version 0.3 to crates.io ? HOT 3
- Inconsistent return for `with_check` HOT 16
- Replace unwrap in examples with `?`
- Consider simplifying the API HOT 2
- Invalid import of function via decode::{self} in tests HOT 1
- Nightly build failed
- Nightly build failed
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bs58-rs.