Skip to main content

BodyDoc

Struct BodyDoc 

Source
pub struct BodyDoc<'a> { /* private fields */ }
Expand description

A read-only view of the request body for partition extraction.

Handed to crate::TenancySpi::resolve_partition so an implementer can pull the partition key out of the document without parsing JSON or touching raw bytes (ADR-014): the proxy scans the body on demand, reading just the field asked for and never materializing a tree. This is the extraction utility the SPI composes over, it deliberately exposes no byte accessor, so the memory-bounded scan is the only way in.

Backed by the raw body (the whole request for single-doc ingest, or one operation’s source line for _bulk). A body that is absent or not a JSON object simply yields None from every lookup.

§Examples

use osproxy_spi::BodyDoc;

let doc = BodyDoc::new(br#"{"tenant_id":"acme","meta":{"region":"eu"}}"#);
assert_eq!(doc.scalar("tenant_id").as_deref(), Some("acme"));
assert_eq!(doc.scalar("meta.region").as_deref(), Some("eu"));
assert_eq!(doc.scalar("missing"), None);

Implementations§

Source§

impl<'a> BodyDoc<'a>

Source

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

Wraps the raw body bytes.

Source

pub fn scalar(&self, path: &str) -> Option<String>

The scalar at a dotted path (e.g. "tenant_id" or "meta.region"), or None if the path is absent, the leaf is not a scalar, or the body is not a JSON object. String leaves are decoded; numbers and bools use their source text. The scan reads only as far as the field and allocates nothing beyond the returned string.

Source

pub fn is_empty(&self) -> bool

Whether the body is empty (no document to read).

Trait Implementations§

Source§

impl<'a> Clone for BodyDoc<'a>

Source§

fn clone(&self) -> BodyDoc<'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 BodyDoc<'a>

Source§

impl<'a> Debug for BodyDoc<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for BodyDoc<'a>

§

impl<'a> RefUnwindSafe for BodyDoc<'a>

§

impl<'a> Send for BodyDoc<'a>

§

impl<'a> Sync for BodyDoc<'a>

§

impl<'a> Unpin for BodyDoc<'a>

§

impl<'a> UnsafeUnpin for BodyDoc<'a>

§

impl<'a> UnwindSafe for BodyDoc<'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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.