您当前的位置: 首页 >  rust

mutourend

暂无认证

  • 1浏览

    0关注

    661博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Rust的hex::encode

mutourend 发布时间:2019-09-17 17:51:31 ,浏览量:1

对应的crate为hex,在Cargo.toml中配置相应的依赖:

[dependencies]
hex = {version = "0.3", default-features = false, optional = true}
pub fn encode(data: T) -> String

会将data转换为以小写字母表示的十六进制字符串。data中的每个byte对应为2个十六进制位,所以十六进制字符串的长度正好是data长度的两倍。

assert_eq!(hex::encode("Hello world!"), "48656c6c6f20776f726c6421");
assert_eq!(hex::encode(vec![1, 2, 3, 15, 16]), "0102030f10");

参考资料: [1] https://docs.rs/hex/0.3.2/hex/fn.encode.html

关注
打赏
1664532908
查看更多评论
立即登录/注册

微信扫码登录

0.0385s