516 Commits
Author SHA1 Message Date
Taiki EndoandGitHub fbc64bcc67 Update loom to 0.7 (#651) 2024-01-08 01:10:48 +09:00
Alice RyhlandGitHub 3bf6583b5c readme: add security policy (#649) 2024-01-03 17:22:39 +01:00
Brad DunbarandGitHub dbbdb63d76 Use self. instead of Self:: (#642)
I was a little confused about these calls using `Self::` instead of
`self.` here. Is there a reason to use the former instead of the latter?
2023-12-28 14:20:13 +09:00
Luca BrunoandGitHub f73c6c8e85 Simplify UninitSlice::as_uninit_slice_mut() logic (#644)
This reworks `UninitSlice::as_uninit_slice_mut()` using equivalent
simpler logic.
2023-12-28 14:17:53 +09:00
Gabriel GollerandGitHub 72cbb92e0e docs: fix broken links (#639)
Fixed a few broken links and converted a lot of them from the
html-link to intra-doc links.
2023-11-16 06:24:21 -05:00
bde8c50703 docs: typo fix (#637)
Co-authored-by: Daniel Bauman <[email protected]>
2023-10-19 21:50:24 +02:00
Alice RyhlandGitHub fd9243f9e2 Various cleanup (#635) 2023-10-02 15:40:02 +02:00
mxsmandGitHub a4e16a552b docs: fix some spelling mistakes (#633) 2023-09-25 10:47:02 +02:00
Lucas KentandGitHub a14ef4617c Move comment to correct constant (#629) 2023-09-11 11:12:11 +02:00
Alice RyhlandGitHub bd9c164cb6 doc: fix changelog typo (#628) 2023-09-07 14:10:55 +02:00
Alice RyhlandGitHub 74e6e200fd chore: prepare bytes v1.5.0 (#627) v1.5.0 2023-09-07 10:52:15 +02:00
Michal NazarewiczandGitHub 64c4fa2867 Rename UninitSlice constructors for consistency with ReadBuf (#599)
tokio::io::ReadBuf uses names `new` and `uninit` for its constructors.
For consistency with that, rename recently introduced UninitSlice
constructors to match those names.
2023-06-20 10:19:56 +02:00
Taiki EndoandGitHub c7756c3e59 Fix CI failure (#616) 2023-06-05 01:04:59 +09:00
Michal NazarewiczandGitHub b29112ce44 Implement BufMut for &mut [MaybeUninit<u8>] (#597) 2023-02-10 10:28:24 +01:00
Michal NazarewiczandGitHub 99a27542a0 Add a safe way to create UninitSlice from slices (#598)
Introduce UninitSlice::from_slice and UninitSlice::from_uninit_slice
methods which safely create Uninit slice from provided slice of maybe
uninitialised or initialised memory.

In addition, add `From<&mut [T]>` implementations (for `T=u8` and
`T=MaybeUninit<u8>`) which do conversion from slice to UninitSlice.

Closes: #552
2023-02-09 17:24:23 +01:00
Paa Kojo SamanpaandGitHub 74b04c7aae Mark BytesMut::extend_from_slice as inline (#595)
This function can be hot in applications that do a lot of encoding. Ideally would do the same for `<BytesMut as BufMut>::put_slice` and `<BytesMut as BufMut::put_u8`.
2023-02-04 20:16:41 +01:00
Alice RyhlandGitHub 21ed332836 chore: prepare bytes v1.4.0 (#593) v1.4.0 2023-01-31 20:38:32 +01:00
brian m. carlsonandGitHub 05e9d5cab9 Avoid large reallocations when freezing BytesMut (#592)
When we freeze a BytesMut, we turn it into a Vec, and then convert that
to a Bytes.  Currently, this happen using Vec::into_boxed_slice, which
reallocates to a slice of the same length as the Vev if the length and
the capacity are not equal.  This can pose a performance problem if the
Vec is large or if this happens many times in a loop.

Instead, let's compare the length and capacity, and if they're the same,
continue to handle this using into_boxed_slice.  Otherwise, since we
have a type of vtable which can handle a separate capacity, the shared
vtable, let's turn our Vec into that kind of Bytes.  While this does not
avoid allocation altogether, it performs a fixed size allocation and
avoids any need to memcpy.
2023-01-31 20:04:22 +01:00
0xc0001a2040andGitHub f15bba3375 Document which functions require std (#591) 2023-01-31 11:42:28 +01:00
c93a94b974 Fix duplicate "the the" typos (#585)
Co-authored-by: Nicolae Mihalache <[email protected]>
2022-12-20 11:49:55 +01:00
Matthijs van OtterdijkandGitHub 050d65b2ce make IntoIter constructor public (#581) 2022-11-25 22:48:20 +01:00
Sean LynchandGitHub 9b227220df chore: prepare bytes v1.3.0 (#579) v1.3.0 2022-11-21 08:06:49 +01:00
Sean LynchandGitHub 8a8c41f5c2 Implement native-endian get and put functions for Buf and BufMut (#576)
Fixes #549
2022-11-14 10:33:36 +01:00
Sean LynchandGitHub 5c7b4317e0 Update nightly snapshot to the current one (#577) 2022-11-14 10:56:33 +09:00
Yotam OfekandGitHub 6e4b1f244b Rename and expose BytesMut::spare_capacity_mut (#572) 2022-10-04 12:23:07 +02:00
Adam ChalmersandGitHub a36f661354 docs: Bytes::new etc should return Self not Bytes (#568) 2022-08-24 13:30:21 +02:00
Alice RyhlandGitHub d1b5d4ceb1 Don't have important data in unused capacity when calling reserve (#563) 2022-08-12 12:22:43 +02:00
Alice RyhlandGitHub b7249149a9 chore: prepare bytes v1.2.1 (#561) v1.2.1 2022-07-30 11:35:26 +02:00
Matt SchulteandGitHub d6e1999d97 Fix reserve over allocating underlying buffer (#560)
Fixes calls to `reserve` when the underlying shared buffer was already
big enough to fit the requested capacity. Previously a new even larger
buffer was created anyways. This could eventually lead to an OOM
condition.
2022-07-30 11:16:32 +02:00
Alice RyhlandGitHub 38fd42acba chore: prepare bytes v1.2.0 (#556) v1.2.0 2022-07-19 13:39:58 +02:00
7553a67be2 Fix amortized asymptotics of BytesMut (#555)
Signed-off-by: Jiahao XU <[email protected]>
Co-authored-by: Frank Steffahn <[email protected]>
2022-07-19 13:17:53 +02:00
cd188cbd67 Add conversion from Bytes to Vec<u8> (#547)
Signed-off-by: Jiahao XU <[email protected]>
Co-authored-by: Alice Ryhl <[email protected]>
2022-07-13 09:04:23 +02:00
Jiahao XUandGitHub 10d1f6ec5c Fix: From<BytesMut> fo Vec<u8> implementation (#554)
Signed-off-by: Jiahao XU <[email protected]>
2022-07-13 08:59:54 +02:00
Jiahao XUandGitHub 068ed41bc0 Add conversion from BytesMut to Vec<u8> (#543) 2022-07-10 12:44:29 +02:00
Alice RyhlandGitHub f514bd38da miri: don't use int2ptr casts for invalid pointers (#553) 2022-07-09 21:54:34 +02:00
Lucio FrancoandGitHub 28a1eab1e0 chore: Fix unused warnings (#551) 2022-06-23 09:16:03 -07:00
ZettrokeandGitHub 3536017ccf Fix chain remaining_mut(), allowing to chain growing buffer (#488) 2022-06-11 13:12:53 +09:00
Erick TryzelaarandGitHub b8d27c016f Add UninitSlice::as_uninit_slice_mut() (#548)
This adds an unsafe method to convert a `&mut UninitSlice` into a
`&mut [MaybeUninit<u8>]`. This method is unsafe because some of the
bytes in the slice may be initialized, and the caller should not
overwrite them with uninitialized bytes.

This came about when auditing [tokio-util's udp frame], where they want
to pass the unitialized portion of a `BytesMut` to [ReadBuf::uninit].
They need to do this unsafe pointer casting in a few places, which
complicates audits. This method lets us document the safety invariants
the caller needs to maintain when doing this conversion.

[tokio-util's udp frame]: https://github.com/tokio-rs/tokio/blob/master/tokio-util/src/udp/frame.rs#L87
[ReadBuf::uninit]: https://docs.rs/tokio/latest/tokio/io/struct.ReadBuf.html#method.uninit
2022-05-10 11:22:19 +02:00
Taiki EndoandGitHub 0ce4fe3c91 Update actions/checkout action to v3 (#546) 2022-05-01 14:50:55 +02:00
Alice RyhlandGitHub 716a0b189e Only avoid pointer casts when using miri (#545) 2022-04-29 22:01:26 +02:00
Alice Ryhl b4b2c18c27 Revert accidental push directly to master
This reverts commit 89061c3238.

Why am I even able to push to master?
2022-04-29 19:49:28 +02:00
Alice Ryhl 89061c3238 Only avoid pointer casts when using miri 2022-04-29 19:47:34 +02:00
Jiahao XUandGitHub 0a2c43af88 Fix bugs in BytesMut::reserve_inner (#544) 2022-04-28 11:37:33 +02:00
Alice RyhlandGitHub 8198f9e28e Make strict provenance compatible (#542) 2022-04-16 00:26:58 +02:00
Alice RyhlandGitHub 547a32033e Add TSAN support (#541) 2022-04-15 22:46:40 +02:00
Ben KimockandGitHub 724476982b Fix aliasing in Clone by using a raw pointer (#523)
Previously, this code produced a &mut[u8] and a Box<[u8]> to the shared
allocation upon cloning it. If the underlying allocation were actually
shared, such as through a &[u8] from the Deref impl, creating either of
these types incorrectly asserted uniqueness of the allocation.

This fixes the example in #522, but Miri still does not pass on this
test suite with -Zmiri-tag-raw-pointers because Miri does not currently
understand int to pointer casts.
2022-04-06 16:59:20 +02:00
Evan CameronandGitHub 9e6edd18d2 Clarify BytesMut::unsplit docs (#535) 2022-04-06 15:19:00 +02:00
Anthony DeschampsandGitHub e4c723697d docs: redraw layout diagram with box drawing characters. (#539)
I find this diagram very helpful, but a little hard to distinguish
between the boxes and the lines that connect them. This commit redraws
the boxes with line drawing characters so that the boxes appear a
little more solid, and stand out from the other lines.
2022-03-25 10:55:13 +01:00
Jiahao XUandGitHub d4f5023383 Optimize BytesMut::reserve: Reuse vec if possible (#529)
* Optimize `BytesMut::reserve`: Reuse vec if possible

If the `BytesMut` holds a unqiue reference to `KIND_ARC` while the
capacity of the `Vec` is not big enough , reuse the existing `Vec`
instead of allocating a new one.

Signed-off-by: Jiahao XU <[email protected]>
2022-03-16 10:11:42 -04:00
Ralf JungandGitHub 88f5e12350 update Miri CI config (#534) 2022-03-09 10:29:04 +01:00