HexUtil

Struct HexUtil 

Source
pub struct HexUtil;

Implementations§

Source§

impl HexUtil

Source

pub fn to_hex(bytes: &[u8]) -> String

将字节数组转换为十六进制字符串表示

§参数
  • bytes - 需要转换的字节切片
§返回值

返回表示输入字节的十六进制字符串,每个字节用两个十六进制字符表示

Source

pub fn encode_hex_str(text: &str) -> String

将字符串编码为十六进制字符串

§参数
  • text - 需要编码的原始字符串
§返回值

返回编码后的十六进制字符串

Source

pub fn decode_hex_str(hex: &str) -> Result<String, &'static str>

将十六进制字符串解码为UTF-8字符串

§参数
  • hex - 要解码的十六进制字符串引用
§返回值
  • Ok(String) - 解码成功的UTF-8字符串
  • Err(&'static str) - 解码失败时的错误信息,可能的错误包括:
    • “Invalid hex string length”:十六进制字符串长度为奇数
    • “Invalid hex digit”:包含无效的十六进制字符
    • “Invalid UTF-8 sequence”:解码后的字节序列不是有效的UTF-8
§示例
let result = decode_hex_str("48656c6c6f"); // 解码为 "Hello"

Auto Trait Implementations§

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> 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> Same for T

Source§

type Output = T

Should always be Self
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.