Git Product home page Git Product logo

Comments (8)

alexcrichton avatar alexcrichton commented on July 16, 2024 4

Sounds like a good idea to me! I'd grow the buffer internally

from bytes.

vorner avatar vorner commented on July 16, 2024 4

I don't think a writer that doesn't grow the buffer is of much use. Usually, when I need a writer, I delegate the encoding or writing to some other code. And often I don't know in advance how much such code will write.

An example of code that would make sense:

use serde_cbor;
use tokio_io::io::Encoder;

struct E;

impl Encoder for E {
  ...
  fn encode(&mut self, item: Self::Item, dst: &mut BytesMut) -> Result<(), Self::Error> {
    serde_cbor::to_writer(dst)
  }
}

Now I have to wrap dst into a newtype that implements writer because it doesn't know how to be a writer (which isn't much work). If it didn't extend the dst as needed, I'd still need to wrap it, because I don't know the size in advance.

from bytes.

carllerche avatar carllerche commented on July 16, 2024

This seems fine to me. My only question is if BytesMut should grow as needed or return an error when it is full.

Thoughts @alexcrichton

from bytes.

carllerche avatar carllerche commented on July 16, 2024

@alexcrichton So BufMut has a writer adapter: BufMut::writer(). That implementation does not grow the buffer. It's built on BufMut::bytes_mut and remaining_mut.

from bytes.

carllerche avatar carllerche commented on July 16, 2024

This is now done: https://docs.rs/bytes/0.5.6/bytes/struct.BytesMut.html#impl-Write

from bytes.

ColinFinck avatar ColinFinck commented on July 16, 2024

@carllerche BytesMut still lacks an implementation of std::io::Write.
What your URL refers to is an implementation of std::fmt::Write, which is something different.

I'd say this issue is still unresolved.

from bytes.

taiki-e avatar taiki-e commented on July 16, 2024

@ColinFinck please see #478

from bytes.

ColinFinck avatar ColinFinck commented on July 16, 2024

Thanks for the reference, @taiki-e
In the meantime, I'm using BufMut::writer on BytesMut.

from bytes.

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.