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
impl Raw
Sourcepub fn from_text(body: impl Into<Box<str>>) -> Self
pub fn from_text(body: impl Into<Box<str>>) -> Self
Keeps a response body exactly as it arrived.
Sourcepub fn json(&self) -> Option<Value>
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.