Struct JsonCodec
pub struct JsonCodec;Trait Implementations§
§impl CratestackCodec for JsonCodec
impl CratestackCodec for JsonCodec
§fn encode_into<T>(
&self,
value: &T,
out: &mut Vec<u8>,
) -> Result<(), CratestackError>
fn encode_into<T>( &self, value: &T, out: &mut Vec<u8>, ) -> Result<(), CratestackError>
serde_json writes into any io::Write, so this appends to out
directly instead of the default’s encode-then-copy.
§fn decode<T>(&self, bytes: &[u8]) -> Result<T, CratestackError>where
T: for<'de> Deserialize<'de>,
fn decode<T>(&self, bytes: &[u8]) -> Result<T, CratestackError>where
T: for<'de> Deserialize<'de>,
Same as serde_json::from_slice (including its trailing-data check),
wrapped in serde_path_to_error so the error’s detail names the field
that failed (failed to decode JSON body: amountE8: invalid type ...).
The public message of CratestackError::Codec stays generic; the path
reaches operators through detail() only.
const CONTENT_TYPE: &'static str = "application/json"
fn encode<T>(&self, value: &T) -> Result<Vec<u8>, CratestackError>
Source§impl HttpClientCodec for JsonCodec
Available on crate feature codec-json only.
impl HttpClientCodec for JsonCodec
codec-json only.fn accept_header_value(&self) -> &'static str
fn sequence_accept_header_value(&self) -> &'static str
fn decode_response<T>(
&self,
content_type: &str,
body: &[u8],
) -> Result<T, CratestackError>where
T: DeserializeOwned,
fn decode_sequence_response<T>(
&self,
content_type: &str,
body: &[u8],
) -> Result<Vec<T>, CratestackError>where
T: DeserializeOwned,
Source§fn payload_accept(&self) -> &'static str
fn payload_accept(&self) -> &'static str
Cratestack-Payload-Accept value: one to eight
lowercase type/subtype entries joined by ", ", in order of
preference. The default is CONTENT_TYPE
alone, which suits a codec that writes and reads the same type;
override it for an asymmetric one (a form in, JSON out). A sealed
call sends the header only when this is not application/cbor, and
the client refuses any answer sealed under a type it does not list.Auto Trait Implementations§
impl Freeze for JsonCodec
impl RefUnwindSafe for JsonCodec
impl Send for JsonCodec
impl Sync for JsonCodec
impl Unpin for JsonCodec
impl UnsafeUnpin for JsonCodec
impl UnwindSafe for JsonCodec
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<C> HttpTransport for Cwhere
C: CratestackCodec,
impl<C> HttpTransport for Cwhere
C: CratestackCodec,
Source§fn can_encode(&self, content_type: &str) -> bool
fn can_encode(&self, content_type: &str) -> bool
content_type
(cratestack#489). RouteTransportCapabilities::response_types
(cratestack-core) is a compile-time list of what the transport
shape can carry (e.g. both CBOR and JSON, for every route), not
what the concrete codec(s) wired into this particular router were
built with — a router constructed with a single JsonCodec still
emits a response_types list that names application/cbor. Read morefn decode_request<T>(
&self,
content_type: &str,
body: &[u8],
) -> Result<T, CratestackError>where
T: for<'de> Deserialize<'de>,
fn encode_response<T>( &self, content_type: &str, status: StatusCode, value: &T, ) -> Result<Response<Body>, CratestackError>
fn encode_sequence_response<T>(
&self,
content_type: &str,
status: StatusCode,
values: &[T],
) -> Result<Response<Body>, CratestackError>where
T: Serialize,
fn encode_sequence_error_response( &self, content_type: &str, status: StatusCode, value: &CratestackErrorResponse, ) -> Result<Response<Body>, CratestackError>
Source§fn encode_sequence_stream_response<T, S>(
&self,
content_type: &str,
status: StatusCode,
values: S,
) -> Result<Response<Body>, CratestackError>
fn encode_sequence_stream_response<T, S>( &self, content_type: &str, status: StatusCode, values: S, ) -> Result<Response<Body>, CratestackError>
Self::encode_sequence_response
for @stream procedures (cratestack#283): values is encoded and
flushed item-by-item via axum::body::Body::from_stream instead
of collected into a Vec first. Only meaningful for
application/cbor-seq — implementations reject any other
content_type, mirroring how the higher-level
encode_transport_stream_result_with_status_for only calls this
when cbor-seq was negotiated (anything else falls back to the
buffered encode_sequence_response path there).§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<'src, T> IntoMaybe<'src, T> for Twhere
T: 'src,
impl<'src, T> IntoMaybe<'src, T> for Twhere
T: 'src,
impl<T> MaybeSend for T
impl<T> MaybeSendSync for T
impl<T> OrderedSeq<'_, T> for Twhere
T: Clone,
§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling [Attribute] value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi [Quirk] value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the [Condition] value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
§impl<'p, T> Seq<'p, T> for Twhere
T: Clone,
impl<'p, T> Seq<'p, T> for Twhere
T: Clone,
§type Iter<'a> = Once<&'a T>
where
T: 'a
type Iter<'a> = Once<&'a T> where T: 'a
§fn contains(&self, val: &T) -> boolwhere
T: PartialEq,
fn contains(&self, val: &T) -> boolwhere
T: PartialEq,
§fn to_maybe_ref<'b>(item: <T as Seq<'p, T>>::Item<'b>) -> Maybe<T, &'p T>where
'p: 'b,
fn to_maybe_ref<'b>(item: <T as Seq<'p, T>>::Item<'b>) -> Maybe<T, &'p T>where
'p: 'b,
MaybeRef].