pub struct SerBuffer;Expand description
Thread-local reusable serialization buffer.
Serializes into one reusable working buffer instead of the one
serde_json::to_vec() builds up on every call. The buffer is cleared (but
not deallocated) between uses. serialize still returns
a new Vec<u8>, a copy of the buffer’s contents;
serialize_into writes to a writer you own and
makes no copy.
§Performance impact
- Small payloads (<256B): measurably faster than
to_vec(see the book’s benchmark page for the current figures). - Large payloads (>1KB): no measurable difference — the payload dominates.
§Thread safety
Each thread gets its own buffer via thread_local!. There is no
cross-thread contention. The buffer is never shared.
Implementations§
Source§impl SerBuffer
impl SerBuffer
Sourcepub fn serialize<T>(value: &T) -> Result<Vec<u8>, Error>where
T: Serialize,
pub fn serialize<T>(value: &T) -> Result<Vec<u8>, Error>where
T: Serialize,
Serializes value into a reusable thread-local buffer and returns
the bytes as a new Vec<u8>.
The thread-local buffer is reused across calls: it is allocated once per
thread, grows as needed and is never deallocated between calls. The
returned Vec<u8> is a copy of its contents.
§Errors
Returns a serde_json::Error if serialization fails.
Auto Trait Implementations§
impl Forget for SerBuffer
impl Freeze for SerBuffer
impl Move for SerBuffer
impl RefUnwindSafe for SerBuffer
impl Send for SerBuffer
impl Sync for SerBuffer
impl Unpin for SerBuffer
impl UnsafeUnpin for SerBuffer
impl UnwindSafe for SerBuffer
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§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<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].