当前位置: 首页>>编程示例 >>用法及示例精选 >>正文


Rust str.into_boxed_bytes用法及代码示例

本文简要介绍rust语言中 str.into_boxed_bytes 的用法。

用法

pub fn into_boxed_bytes(self: Box<str, Global>) -> Box<[u8], Global>

Box<str> 转换为 Box<[u8]> 而不复制或分配。

例子

基本用法:

let s = "this is a string";
let boxed_str = s.to_owned().into_boxed_str();
let boxed_bytes = boxed_str.into_boxed_bytes();
assert_eq!(*boxed_bytes, *s.as_bytes());

相关用法


注:本文由纯净天空筛选整理自rust-lang.org大神的英文原创作品 str.into_boxed_bytes。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。