Giter VIP home page Giter VIP logo

Comments (3)

zslayton avatar zslayton commented on August 16, 2024

Yeah, this is something I've stubbed my toe on too. I initially held off on it because I had (have!) hope that we'll add an API to re-use a writer's existing resources to start a new stream while avoiding reallocations. That's something I can easily add a separate method for though.

Should finish() return the output so you don't have to remember to pass a &mut?

In the meantime, the writer API has a fn output(&self) -> &Self::Output method (and a mut_output) that lets you get a handle to the output source without dropping the writer.

let mut sink = Vec::new();
let mut writer = TextWriterBuilder::default().build(&mut sink)?;
writer.write_symbol("foo")?;
writer.flush()?;
assert_eq!(writer.output(), "foo".as_bytes());

Not ideal, but often good enough for simple uses like unit tests.

from ion-rust.

sadderchris avatar sadderchris commented on August 16, 2024

Should finish() return the output so you don't have to remember to pass a &mut?

Yes, that would be excellent.

In the meantime, the writer API has a fn output(&self) -> &Self::Output method (and a mut_output) that lets you get a handle to the output source without dropping the writer.

This only really works if you don't need to pass along ownership of the sink, which we're often doing. Like you said, good for unit tests, but impractical for real-world code.

from ion-rust.

desaikd avatar desaikd commented on August 16, 2024

Completed with #720

from ion-rust.

Related Issues (20)

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.