Comments (8)
Unless someone has an idea to workaround this problem and has real arguments wrt the cost of adding the lenth to GenResult, I'm going to add it back.
from cookie-factory.
Poke @sdroege as you were the one to drop it
from cookie-factory.
Thinking back of the examples from above, there is even a way to be closer to the "length-less" approach by just using .0
for the serializers we provide, and then just not using GenResult but a simple Result<Foo, GenError>
in custom serializers:
let buf = foo(buf)?.0;
let buf = bar(buf)?.0;
Ok(buf)
from cookie-factory.
introducing hacks such as BackToTheBuffer
I wouldn't call this a hack but it's a useful combinator to have regardless of everything else.
Thinking back of the examples from above, there is even a way to be closer to the "length-less" approach by just using
.0
for the serializers we provide, and then just not using GenResult but a simpleResult<Foo, GenError>
in custom serializers:let buf = foo(buf)?.0; let buf = bar(buf)?.0; Ok(buf)
You can't do this when writing combinators yourself. Inside your own combinators you would always have to ensure to pass through the length correctly everywhere and add it correctly together, which is a rather error-prone and manual job.
In every SerializeFn
that is not just a combination of combinators (i.e. you have to write the closure yourself), you would have to keep track of the lengths correctly. I don't think that scales well either.
And you'd have to bring back hacks like the GenResult
combinators and using the normal Result
combinators would break the expected behaviour (as the length wouldn't be accumulated).
I think passing through the length as-is is not really the solution we're looking for here.
from cookie-factory.
Or to summarize: returning the length directly would make it impossible to use the Result
combinators and you need something to add together the lengths. And don't ever accidentally use any of the Result
combinators, or do a mistake in accumulating the lengths, or otherwise everything will fall apart.
from cookie-factory.
Maybe a mix of the previous and the current approach with some tuple such as the WriteCounter would make sense?
let buf = (buf, 0);
let buf = foo(buf)?;
let buf = bar(buf)?;
Ok(buf)
from cookie-factory.
You mean to pass not a Write
though the combinators but instead some pub struct Blabla<W: Write>(W, usize)
, and have everything operate on that struct instead of Write
(and have it proxy the Write
API)?
That would work I guess, the only disadvantages would be
- We would always calculate the lengths but the performance impact can be ignored IMHO
- If you have a combinator that requires a specific
Write
impl, you still need the possibility to poke it out of the struct, do your stuff, put the updated value back and then also correctly update theusize
Seems acceptable to me. We could call this struct WriteContext
maybe
from cookie-factory.
Doing a test implementation of that now btw
from cookie-factory.
Related Issues (16)
- 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
- Add a way to skip bytes in WriteCounter HOT 6
- 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
- license file no longer included in published crates since 0.3.3
- 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.