Code Monkey home page Code Monkey logo

Comments (8)

Keruspe avatar Keruspe commented on September 21, 2024

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.

Keruspe avatar Keruspe commented on September 21, 2024

Poke @sdroege as you were the one to drop it

from cookie-factory.

Keruspe avatar Keruspe commented on September 21, 2024

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.

sdroege avatar sdroege commented on September 21, 2024

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 simple Result<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.

sdroege avatar sdroege commented on September 21, 2024

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.

Keruspe avatar Keruspe commented on September 21, 2024

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.

sdroege avatar sdroege commented on September 21, 2024

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 the usize

Seems acceptable to me. We could call this struct WriteContext maybe

from cookie-factory.

sdroege avatar sdroege commented on September 21, 2024

Doing a test implementation of that now btw

from cookie-factory.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.