Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
- move weak reference and downcasting examples into module docs
- expand module introduction describing use cases
- document rationale for separating `ByteSource` and `ByteOwner`
- summarize built-in `ByteSource`s and show how to extend them
- clarify library overview and development instructions in README
30 changes: 30 additions & 0 deletions src/sources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,36 @@
* LICENSE file in the root directory of this source tree.
*/

//! Implementations of [`ByteSource`] for common byte containers.
//!
//! | Feature | Implementations |
//! | ------------ | ---------------------------------------------------------------- |
//! | `zerocopy` | `&'static [T]`, `Box<T>` and `Vec<T>` for `T: IntoBytes + Immutable` |
//! | *(none)* | `&'static [u8]`, `Box<[u8]>`, `Vec<u8>`, `String`, `&'static str` |
//! | `bytes` | `bytes::Bytes` |
//! | `ownedbytes` | `ownedbytes::OwnedBytes` |
//! | `mmap` | `memmap2::Mmap` and `ByteOwner` for `memmap2::MmapRaw` |
//! | `pyo3` | `pyo3::Bound<'_, PyBytes>` and `ByteOwner` for `Py<PyBytes>` |
//!
//! To store bytes in your own type, implement [`ByteSource`].
//! [`ByteOwner`] is provided automatically for all `ByteSource`s but can be
//! implemented manually if needed:
//!
//! ```rust
//! use anybytes::{ByteSource, Bytes};
//!
//! struct MyData(Vec<u8>);
//!
//! unsafe impl ByteSource for MyData {
//! type Owner = Self;
//!
//! fn as_bytes(&self) -> &[u8] { &self.0 }
//! fn get_owner(self) -> Self::Owner { self }
//! }
//!
//! # let _ = Bytes::from_source(MyData(vec![1, 2, 3]));
//! ```

use zerocopy::Immutable;
#[cfg(feature = "zerocopy")]
use zerocopy::IntoBytes;
Expand Down