Skip to main content

AsSharedBytes

Trait AsSharedBytes 

Source
pub trait AsSharedBytes {
    // Required method
    fn as_bytes_slice(&self) -> &[u8] ⓘ;

    // Provided method
    fn as_shared(&self) -> Option<Bytes> { ... }
}
Expand description

A value a bytes field can encode from: every ProtoBytes representation, plus the borrowed &[u8] that view types carry.

This exists so put_shared_bytes_field can serve the duck-typed write_to bodies codegen shares between owned messages and views. The borrowed form has no owned handle to share (as_shared is None); a Rope sink can still capture it zero-copy through its backing-buffer containment check.

Required Methods§

Source

fn as_bytes_slice(&self) -> &[u8] ⓘ

The value’s bytes.

Provided Methods§

Source

fn as_shared(&self) -> Option<Bytes>

A reference-counted handle to exactly the bytes of as_bytes_slice, when one exists.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl AsSharedBytes for &[u8]

Source§

fn as_bytes_slice(&self) -> &[u8] ⓘ

Implementors§