Comments (10)
Sorry for my vague description. I meant some kind of adapter between a stream of bytes in for examples Windows-1252 and a stream of bytes in utf-8. The unicode stream would be very nice, but there's a lot of code that already works with std::io::Read
.
from rust-encoding.
I have to write these impls for a project of mine and would also like to hear whether @lifthrasiir thinks they might be in scope for this crate.
I've also started a conversation on the encoding_rs
crate: hsivonen/encoding_rs#8
from rust-encoding.
It sounds like you want something that implements not std::io::Read
(which is a stream of bytes) but another trait for a Unicode stream. But as discussed in this RFC: rust-lang/rfcs#57, doing it for reading is tricky. The bytes one takes a &mut [u8]
argument, writes to it, and returns the number of written bytes. But doing that with &mut str
might require some zeroing, or something. The contents of str
must be well-formed UTF-8.
I’m experimenting with things that could help here. I’ll post again where there’s something more fully formed to show.
from rust-encoding.
That sounds like it could be built on top of "raw" decoders.
from rust-encoding.
… probably with an impl of encoding::types::StringWriter
for &mut [u8]
, to be used with the argument to Read::read
.
from rust-encoding.
Any progress?
Anything changed since last time that would make it easier?
from rust-encoding.
I just came across the same myself. Would this be something that is in the scope of the crate?
from rust-encoding.
To cross pollinate a bit here from the encoding_rs
crate... @SimonSapin and I worked on our own versions of Read
trait implementations (except @SimonSapin did quite a bit more!). @SimonSapin's work is in this PR: hsivonen/encoding_rs#9 My work is here: https://github.com/BurntSushi/ripgrep/blob/75f1855a91ca00b5d0e62740595b1b91bc5142a2/src/decoder.rs
The big idea here is that implementing these traits is quite tricky, and neither of our implementations is fully correct. Mine gets most of the way there, but doesn't support single-byte-reads, which means the bytes
adapter method doesn't work at all. It's possible to make this work, but requires a bit more book-keeping.
from rust-encoding.
I wonder if the traits are misdesigned for non utf-8 usage. It's weird that they work with both strings and bytes.
from rust-encoding.
In my case, I very much wanted to ever avoid materializing a &str
and the costs associated with it. So operating on &[u8]
is perfect.
from rust-encoding.
Related Issues (20)
- `encoding::Encoding` cannot be shared between threads safely HOT 1
- warning: private trait in public interface (error E0445) HOT 1
- `all::encodings()` returns an errornous list (and should be sorted alphabetically). HOT 4
- Charset request: ArmSCII-8 HOT 4
- How to Reset a RawDecoder HOT 1
- Implement common traits for Encoding HOT 1
- include LICENSE text to subcrates HOT 3
- C1 are part of ISO-8859-1 (as far as the IANA is concerned)
- Use Cow?
- cp437 HOT 1
- Add Support For CP850
- Warnings emited when building
- Performance: Consider replacing lookup tables with match statements or binary search in single byte index
- request for no_std support
- Abandoned? HOT 2
- to GBK and to UTF8 is not right work
- Community activeness
- Use FM-index & json for DBCS decoding. HOT 3
- Need the performance data for rust-encoding. HOT 1
- Issue with multi-codepoint graphemes HOT 2
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 rust-encoding.