Struct Format
pub struct Format<'a> { /* private fields */ }Expand description
Shared hex representation for encoding and decoding.
Defaults to lowercase without a prefix or separator. Decoding accepts either digit case and requires the configured prefix and separators exactly. Configuration only borrows text; it never allocates. Both strings share a lifetime, shortened as needed when combining independently borrowed values.
use rama_utils::{fmt::hex, hex::Format};
const FORMAT: Format<'static> = Format::new()
.with_upper_case().with_prefix("hash:").with_separator(":");
let view = hex(&[0, 0xab, 255]).with_format(FORMAT);
assert_eq!(view.to_string(), "hash:00:AB:FF");
assert_eq!(FORMAT.decode::<[u8; 3]>("hash:00:aB:ff")?, [0, 0xab, 255]);Implementations§
§impl Format<'_>
impl Format<'_>
pub fn serialize<S, B>(
&self,
bytes: &B,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
Available on crate features grpc and http and std only.
pub fn serialize<S, B>( &self, bytes: &B, serializer: S, ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
grpc and http and std only.Serialize byte-like input with this format, without an intermediate hex string unless the serializer itself needs one.
pub fn deserialize<'de, D, T>(
&self,
deserializer: D,
) -> Result<T, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
T: FromHex,
Available on crate features grpc and http and std only.
pub fn deserialize<'de, D, T>(
&self,
deserializer: D,
) -> Result<T, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
T: FromHex,
grpc and http and std only.Deserialize into a FromHex destination using this format.
§impl Format<'_>
impl Format<'_>
pub fn decode<T>(&self, input: impl AsRef<[u8]>) -> Result<T, DecodeError>where
T: FromHex,
Available on crate features grpc and http and std only.
pub fn decode<T>(&self, input: impl AsRef<[u8]>) -> Result<T, DecodeError>where
T: FromHex,
grpc and http and std only.Decode using this format, accepting either digit case and requiring the configured prefix and separators. All input must be consumed.
pub fn decode_into<'out, B>(
&self,
input: impl AsRef<[u8]>,
output: &'out mut B,
) -> Result<&'out mut [u8], DecodeError>
Available on crate features grpc and http and std only.
pub fn decode_into<'out, B>( &self, input: impl AsRef<[u8]>, output: &'out mut B, ) -> Result<&'out mut [u8], DecodeError>
grpc and http and std only.Decode with this format into the start of an existing buffer.
See decode_into for destination and error behavior.
pub fn decode_append<B>(
&self,
input: impl AsRef<[u8]>,
output: &mut B,
) -> Result<usize, DecodeError>
Available on crate features grpc and http and std only.
pub fn decode_append<B>( &self, input: impl AsRef<[u8]>, output: &mut B, ) -> Result<usize, DecodeError>
grpc and http and std only.Append bytes decoded with this format to a growing collection.
See decode_append for destination and error behavior.
pub fn decode_write<W>(
&self,
input: impl AsRef<[u8]>,
output: &mut W,
) -> Result<usize, DecodeWriteError>
Available on crate features grpc and http and std only.
pub fn decode_write<W>( &self, input: impl AsRef<[u8]>, output: &mut W, ) -> Result<usize, DecodeWriteError>
grpc and http and std only.Write bytes decoded with this format to an I/O destination.
See decode_write for validation and partial-write behavior.
§impl<'a> Format<'a>
impl<'a> Format<'a>
pub const fn new() -> Format<'a>
Available on crate features grpc and http and std only.
pub const fn new() -> Format<'a>
grpc and http and std only.Lowercase, unprefixed hex.
pub const fn with_lower_case(self) -> Format<'a>
Available on crate features grpc and http and std only.
pub const fn with_lower_case(self) -> Format<'a>
grpc and http and std only.Select lowercase hex digits. Decoding always accepts both cases.
pub fn set_lower_case(&mut self) -> &mut Format<'a>
Available on crate features grpc and http and std only.
pub fn set_lower_case(&mut self) -> &mut Format<'a>
grpc and http and std only.Select lowercase hex digits. Decoding always accepts both cases.
pub const fn with_upper_case(self) -> Format<'a>
Available on crate features grpc and http and std only.
pub const fn with_upper_case(self) -> Format<'a>
grpc and http and std only.Select uppercase hex digits. Decoding always accepts both cases.
pub fn set_upper_case(&mut self) -> &mut Format<'a>
Available on crate features grpc and http and std only.
pub fn set_upper_case(&mut self) -> &mut Format<'a>
grpc and http and std only.Select uppercase hex digits. Decoding always accepts both cases.
pub const fn with_prefix(self, prefix: &'a str) -> Format<'a>
Available on crate features grpc and http and std only.
pub const fn with_prefix(self, prefix: &'a str) -> Format<'a>
grpc and http and std only.Select a literal prefix, required exactly once when decoding. An empty string disables the prefix.
pub fn set_prefix(&mut self, prefix: &'a str) -> &mut Format<'a>
Available on crate features grpc and http and std only.
pub fn set_prefix(&mut self, prefix: &'a str) -> &mut Format<'a>
grpc and http and std only.Select a literal prefix, required exactly once when decoding. An empty string disables the prefix.
pub const fn with_separator(self, separator: &'a str) -> Format<'a>
Available on crate features grpc and http and std only.
pub const fn with_separator(self, separator: &'a str) -> Format<'a>
grpc and http and std only.Insert this literal separator between bytes, never at either end.
Decoding requires it at every byte boundary. An empty separator selects compact hex. Any UTF-8 text, including hex digits, is supported; decoding uses fixed two-digit byte groups rather than splitting on the separator.
pub fn set_separator(&mut self, separator: &'a str) -> &mut Format<'a>
Available on crate features grpc and http and std only.
pub fn set_separator(&mut self, separator: &'a str) -> &mut Format<'a>
grpc and http and std only.Insert this literal separator between bytes, never at either end.
Decoding requires it at every byte boundary. An empty separator selects compact hex. Any UTF-8 text, including hex digits, is supported; decoding uses fixed two-digit byte groups rather than splitting on the separator.
Trait Implementations§
impl<'a> Copy for Format<'a>
impl<'a> Eq for Format<'a>
impl<'a> StructuralPartialEq for Format<'a>
Auto Trait Implementations§
impl<'a> Freeze for Format<'a>
impl<'a> RefUnwindSafe for Format<'a>
impl<'a> Send for Format<'a>
impl<'a> Sync for Format<'a>
impl<'a> Unpin for Format<'a>
impl<'a> UnsafeUnpin for Format<'a>
impl<'a> UnwindSafe for Format<'a>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§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 rama_grpc::Request§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§fn and<P, B, E>(self, other: P) -> And<T, P>
fn and<P, B, E>(self, other: P) -> And<T, P>
Policy that returns Action::Follow only if self and other return
Action::Follow. Read more