Comments (6)
from cookie-factory.
What I was thinking of is a combinator (not combinatorial! thanks autocorrect) like
fn split_at<W, R>(idx: usize, pre_write: F, post_write: G) -> SerializeFn<W>
where
G: Fn(W) -> GenResult<(W, R)>,
F: Fn(W, R) -> GenResult<W>
And a trait basically allowing to perform that above action. G
would be a serializing function that is called first for the part at/after the index and returns some value together with the writer, F
would be a serializing function that is called second for the part before the index and gets the return value of G
passed (and I guess many implementations of the trait would panic if F
does not write the whole of the part before the index). And the whole thing is then returning the writer that is returned by G
(i.e. at the position after G
finished, after the block that F
and G
wrote).
This could be trivially implemented for byte slices for what you need, and could also be implemented for e.g. Cursor<&mut [u8]>
(via set_position() to jump temporarily backwards) or for any writer that also implements
Seek` (in the same way).
What do you think? Do I miss something? I didn't try implementing it yet :)
from cookie-factory.
from cookie-factory.
I'm bad at naming things, see WriteCounter
:D If you have better suggestions, just say so.
from cookie-factory.
from cookie-factory.
from cookie-factory.
Related Issues (15)
- GenError doesn't implement std::error::Error
- RFC: make BufferTooSmall error carry the missing space instead of the space the failing combinator needs
- Change SerializeFn to not return input and written length HOT 10
- Find a way to « resume » an action HOT 2
- Module hierarchy like in nom? HOT 6
- Bring back length in GenResult? HOT 8
- Milestone for 0.3? HOT 2
- Build fails on latest nightly due to repeated identifier HOT 2
- GenError not comparible HOT 1
- Publish next release? HOT 2
- Serializing bits. HOT 1
- `back_to_the_buffer` cannot easily be used recursively HOT 1
- gen_many macros and iterators
- gen_le_i32! refuses to accept negative arguments HOT 1
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 cookie-factory.