Comments (3)
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.
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.
Completed with #720
from ion-rust.
Related Issues (20)
- Write support for e-expressions
- Constant time access of template struct fields
- Merge the `LazySystemReader` and the `LazyExpandingReader`
- Backport expression caching into the Ion 1.0 readers
- Break up `element_test_vectors` to improve test build times HOT 1
- Revisit `annotate` extension method name
- Add type-specific `write` methods to the `StructWriter` trait
- VarUInt encoding is incorrect for sufficiently large `u64`s
- Make discoverable placeholder container writer methods
- Add methods for writing FlexUInt/FlexInt smaller than 64 bits
- Remove feature gate for `Encoding` HOT 3
- Binary write support for delimited containers
- Binary write support for length-prefixed containers
- Serde support should include `from_reader`/`to_writer`, not just `from_ion`/`to_pretty`/`to_string`/`to_binary`
- Performance regression testing for Ion 1.1
- Test runner for Ion 1.1 test vectors
- Binary read support for Ion 1.1 annotation sequences
- Binary write support for Ion 1.1 annotation sequences HOT 1
- Prototype automatic macro generation
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 ion-rust.