Skip to main content

Raw

Struct Raw 

Source
pub struct Raw(/* private fields */);
Expand description

What a provider actually sent, for everything kasapay does not model.

Every Charge carries one. It is the escape hatch: a provider will always have a field somebody needs and this crate has not heard of, and the alternative to keeping the body is losing it.

§Why this is not a serde_json::Value

It used to be. That put serde_json in the public API of every provider adapter, including ones written outside this workspace — the day serde_json goes to 2.0, every one of them breaks for a reason its author did not cause. A provider that answers XML, or a form body, or a protobuf had nowhere to put it either.

So the body is held as text and parsed on request. Raw::json is the one place serde_json appears, and a provider that has no JSON can still build a Raw with Raw::from_text.

§It does not print itself

Debug shows the length and nothing else. A body from a payment provider carries whatever they chose to send — an IBAN, a masked card number, a buyer’s address, an identity number — and Raw is on Charge, on every stored card and on every sub-merchant. One tracing::debug!("{charge:?}") would put all of it in a log file that outlives the request.

Reading it is deliberate: Raw::as_str, Raw::json, Raw::text_at.

Implementations§

Source§

impl Raw

Source

pub fn from_text(body: impl Into<Box<str>>) -> Self

Keeps a response body exactly as it arrived.

Source

pub fn from_json(value: &Value) -> Self

Keeps a body a provider has already parsed.

Source

pub fn as_str(&self) -> &str

The body as it arrived.

Source

pub fn is_empty(&self) -> bool

Whether there is a body at all.

Source

pub fn json(&self) -> Option<Value>

Parses the body as JSON.

Returns None for a body that is not JSON, including an empty one. This is the only method that names serde_json; reach for it when a field kasapay does not model is worth reading.

Source

pub fn text_at(&self, pointer: &str) -> Option<String>

Reads one string out of a JSON body by RFC 6901 pointer.

raw.text_at("/transactionDetail/currencyCode"). Returns None if the body is not JSON, the pointer finds nothing, or what it finds is not a string. Costs a parse, so Raw::json is better for reading several.

Trait Implementations§

Source§

impl Clone for Raw

Source§

fn clone(&self) -> Raw

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 Debug for Raw

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Raw

Source§

fn default() -> Raw

Returns the “default value” for a type. Read more
Source§

impl Display for Raw

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Eq for Raw

Source§

impl From<&Value> for Raw

Source§

fn from(value: &Value) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Raw

Source§

fn eq(&self, other: &Raw) -> bool

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

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Raw

Auto Trait Implementations§

§

impl Freeze for Raw

§

impl RefUnwindSafe for Raw

§

impl Send for Raw

§

impl Sync for Raw

§

impl Unpin for Raw

§

impl UnsafeUnpin for Raw

§

impl UnwindSafe for Raw

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.