pub struct BodyCapture<'a> { /* private fields */ }Expand description
Borrowed HTTP body bytes with truthful source-length metadata.
§Type Parameters
'a- Lifetime of the borrowed body bytes.
Implementations§
Source§impl<'a> BodyCapture<'a>
impl<'a> BodyCapture<'a>
Sourcepub fn prefix(bytes: &'a [u8], max_bytes: usize) -> Self
pub fn prefix(bytes: &'a [u8], max_bytes: usize) -> Self
Captures at most max_bytes from a complete source body.
§Parameters
bytes- Complete source body bytes.max_bytes- Maximum prefix length to expose to the redactor.
§Returns
A complete capture when the body fits, otherwise a truncated prefix carrying the exact total source length. A zero limit captures an empty prefix of non-empty input.
Sourcepub const fn truncated_unknown(bytes: &'a [u8]) -> Self
pub const fn truncated_unknown(bytes: &'a [u8]) -> Self
Sourcepub const fn truncated(
bytes: &'a [u8],
total_len: Option<usize>,
) -> Result<Self, BodyCaptureError>
pub const fn truncated( bytes: &'a [u8], total_len: Option<usize>, ) -> Result<Self, BodyCaptureError>
Creates a capture known to omit source bytes.
§Parameters
bytes- Captured prefix of the source body.total_len- Exact complete source length, orNonewhen unknown.
§Returns
A checked truncated capture.
§Errors
Returns BodyCaptureError::InvalidTotalLength when a known total is
less than or equal to the captured slice length.
Sourcepub const fn bytes(self) -> &'a [u8] ⓘ
pub const fn bytes(self) -> &'a [u8] ⓘ
Returns the body bytes available before the redactor’s hard budget.
§Returns
The borrowed captured byte slice.
Sourcepub const fn captured_len(self) -> usize
pub const fn captured_len(self) -> usize
Sourcepub const fn total_len(self) -> Option<usize>
pub const fn total_len(self) -> Option<usize>
Returns the complete source length when known.
§Returns
Some(total) for an exact length, or None for a truncated capture
whose omitted byte count is unknown.
Sourcepub const fn omitted_len(self) -> Option<usize>
pub const fn omitted_len(self) -> Option<usize>
Returns the number of source bytes omitted before capture.
§Returns
Some(0) for complete input, Some(count) for a known truncated
total, or None when the total length is unknown.
Sourcepub const fn is_source_truncated(self) -> bool
pub const fn is_source_truncated(self) -> bool
Reports whether source bytes were omitted before capture.
§Returns
true for captures created with Self::prefix when the source does
not fit, Self::truncated_unknown, or Self::truncated.
Trait Implementations§
Source§impl<'a> Clone for BodyCapture<'a>
impl<'a> Clone for BodyCapture<'a>
Source§fn clone(&self) -> BodyCapture<'a>
fn clone(&self) -> BodyCapture<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl<'a> Copy for BodyCapture<'a>
Source§impl Debug for BodyCapture<'_>
impl Debug for BodyCapture<'_>
Source§fn fmt(&self, formatter: &mut Formatter<'_>) -> Result
fn fmt(&self, formatter: &mut Formatter<'_>) -> Result
Formats safe capture metadata without exposing body bytes.
§Parameters
formatter- Destination formatting context.
§Returns
The formatter result from writing the safe metadata.
§Errors
Returns fmt::Error when the destination rejects a write.