Skip to main content

BodyCapture

Struct BodyCapture 

Source
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.

§Examples

use qubit_redact::{Redactor, RedactionReason};
use qubit_redact::formats::http::BodyCapture;

let capture = BodyCapture::truncated(b"prefix", 12).expect("valid source length");
assert_eq!(capture.omitted_len(), Some(6));
let output = Redactor::standard().redact_http_body(capture, None);
assert!(output.summary().reasons().contains(RedactionReason::SourceTruncated));

Implementations§

Source§

impl<'a> BodyCapture<'a>

Source

pub const fn complete(bytes: &'a [u8]) -> Self

Creates a capture containing the complete source body.

§Parameters
  • bytes - Complete source body bytes.
§Returns

A capture whose total length equals the borrowed slice length.

Source

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.

Source

pub const fn truncated_unknown(bytes: &'a [u8]) -> Self

Creates a capture known to omit an unknown number of source bytes.

§Parameters
  • bytes - Captured prefix of the source body.
§Returns

An infallible truncated capture whose complete source length is unknown.

Source

pub const fn truncated( bytes: &'a [u8], total_len: 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, which must exceed the captured prefix length.
§Returns

A checked truncated capture.

§Errors

Returns BodyCaptureError::InvalidTotalLength when total_len is less than or equal to the captured slice length. Use Self::truncated_unknown when the complete source length is unknown.

Source

pub const fn bytes(self) -> &'a [u8]

Returns the body bytes available before the redactor’s hard budget.

§Returns

The borrowed captured byte slice.

Source

pub const fn captured_len(self) -> usize

Returns the number of captured bytes.

§Returns

The borrowed slice length.

#![deny(unused_must_use)]
use qubit_redact::formats::http::BodyCapture;

BodyCapture::complete(b"payload").captured_len();
Source

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.

Source

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.

Source

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>

Source§

fn clone(&self) -> BodyCapture<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Copy for BodyCapture<'a>

Source§

impl Debug for BodyCapture<'_>

Source§

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.

Source§

impl<'a> Eq for BodyCapture<'a>

Source§

impl<'a> PartialEq for BodyCapture<'a>

Source§

fn eq(&self, other: &BodyCapture<'a>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<'a> StructuralPartialEq for BodyCapture<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for BodyCapture<'a>

§

impl<'a> RefUnwindSafe for BodyCapture<'a>

§

impl<'a> Send for BodyCapture<'a>

§

impl<'a> Sync for BodyCapture<'a>

§

impl<'a> Unpin for BodyCapture<'a>

§

impl<'a> UnsafeUnpin for BodyCapture<'a>

§

impl<'a> UnwindSafe for BodyCapture<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.