Code Monkey home page Code Monkey logo

Comments (6)

sdroege avatar sdroege commented on June 5, 2024

from cookie-factory.

sdroege avatar sdroege commented on June 5, 2024

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.

Keruspe avatar Keruspe commented on June 5, 2024

from cookie-factory.

sdroege avatar sdroege commented on June 5, 2024

I'm bad at naming things, see WriteCounter :D If you have better suggestions, just say so.

from cookie-factory.

Keruspe avatar Keruspe commented on June 5, 2024

from cookie-factory.

Keruspe avatar Keruspe commented on June 5, 2024

from cookie-factory.

Related Issues (15)

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.