Comments (13)
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.
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.
from bytes.
@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.
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.
@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.
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.
put_u8
depends on remaining_mut
(it is a trait fn).
from bytes.
Basically, this fn: https://github.com/carllerche/bytes/blob/master/src/buf/buf_mut.rs#L270-L293
from bytes.
@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.
@cramertj the remaining_mut
function behavior needs to change https://github.com/carllerche/bytes/blob/master/src/buf/buf_mut.rs#L273.
from bytes.
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.
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.
I'm closing this in favor of #170.
from bytes.
Related Issues (20)
- Need to obtain remaining buffer space HOT 1
- Potential to modify ordering for load in bytes.rs and bytes_mut.rs HOT 2
- Feature Request: Default implementations for heap types which support the unstable allocator API HOT 4
- Feature Request: Default implementations for pinned types HOT 2
- Feature Request: Seekable Buffer ("SeekBuf") and cursor/iterator support HOT 2
- `BufMut` does not include safety invariants in trait documentation HOT 1
- Enable shrinking of allocations
- Contradictory allocation behaviour compared to documentation HOT 9
- Confusing documentation around `Arc<[u8]>` compatibility HOT 1
- Should clone benchmark use use `test::blackbox`? HOT 1
- Explicitly guarantee `Bytes` to be immutable HOT 2
- Expose UTF-8 validated string type HOT 2
- Buf::chunks_vectored() is wrong if chunk() isn't the whole buf HOT 3
- Feature request: fallible version of `BytesMut::unsplit` (i.e. make `BytesMut::try_unsplit` public) HOT 2
- Test for unknown --cfg flags in ci
- Splice for BytesMut HOT 2
- Consider replacing Bytes::make_mut by impl From<Bytes> for BytesMut HOT 5
- Is the conversion from bytes to Vec<u8> O(1) HOT 5
- Feature request: implement `From<Cow<'static, [u8]>>` for `Bytes`
- BytesMut::zeroed doc header improvement HOT 3
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 bytes.