Git Product home page Git Product logo

Comments (13)

alexcrichton avatar alexcrichton commented on July 16, 2024 1

I agree these should be consistent. If we change the behavior of Vec I'd consider it a breaking change, and if we changed the behavior of BytesMut I would not personally at least consider it a breaking change.

I would personally advocate for Vec's strategy.

from bytes.

carllerche avatar carllerche commented on July 16, 2024

My original thought was that I didn't want buffers to implicitly grow. I think this is a common case in networking scenarios. I often have code that fill as much of the buffer as possible then write flush, then fill more. This specifically shows up in how BufMut is implemented. Code that is generic over BufMut look at the remaining argument and if the buffer implicitly grows then the return value of remaining is usize::MAX.

That said, I understand that the inconsistency is not great and could be convinced to switch.

This change would be a breaking change I believe. I know that I would have a bunch of code that semantically breaks.

Cc @alexcrichton

from bytes.

carllerche avatar carllerche commented on July 16, 2024

@alexcrichton implementing this change in BytesMut would expose any existing code using BytesMut to DOS attacks... sounds like a breaking change to me :)

from bytes.

cramertj avatar cramertj commented on July 16, 2024

I'm confused-- if your usages always reserve the necessary space and then fill the buffer, why would it be a breaking change to changing the buffer to autofill if you didn't reserve the necessary space? It shouldn't affect this use case at all. Do you have code that relies on BytesMut panicing in order to ensure correctness?

from bytes.

carllerche avatar carllerche commented on July 16, 2024

@cramertj put_u8 is a helper fn that is provided by BufMut. The breaking change is BufMut::remaining_mut(). To support this change, BufMut::remaining_mut() would have to return usize::MAX instead of the current remaining capacity.

Any code that relies on remaining_mut to return the remaining capacity would break.

from bytes.

cramertj avatar cramertj commented on July 16, 2024

Why would you change the behavior of remaining_mut? It seems reasonable to leave it as a check on the remaining capacity, not the remaining possible size.

from bytes.

carllerche avatar carllerche commented on July 16, 2024

put_u8 depends on remaining_mut (it is a trait fn).

from bytes.

carllerche avatar carllerche commented on July 16, 2024

Basically, this fn: https://github.com/carllerche/bytes/blob/master/src/buf/buf_mut.rs#L270-L293

from bytes.

cramertj avatar cramertj commented on July 16, 2024

@carllerche Couldn't you change put_slice to expand the buffer instead of panicing? I don't see why that would be a breaking change unless someone was relying on the panic occurring.

from bytes.

carllerche avatar carllerche commented on July 16, 2024

@cramertj the remaining_mut function behavior needs to change https://github.com/carllerche/bytes/blob/master/src/buf/buf_mut.rs#L273.

from bytes.

cramertj avatar cramertj commented on July 16, 2024

Why does it need to change? remaining_mut could just refer to the remaining capacity without allocating rather than the remaining possible capacity. Then you can remove that assertion entirely, and replace it with an ensure_capacity call.

from bytes.

carllerche avatar carllerche commented on July 16, 2024

Ah, I see, have BytesMut re-implement all of the fns w/o relying on remaining_mut.

I guess that could work... I'd have to consider it more.

from bytes.

carllerche avatar carllerche commented on July 16, 2024

I'm closing this in favor of #170.

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.