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


Rust CharIndices.offset用法及代码示例


本文简要介绍rust语言中 core::str::CharIndices.offset 的用法。

用法

pub fn offset(&self) -> usize

返回下一个字符的字节位置,如果没有更多字符,则返回基础字符串的长度。

例子

#![feature(char_indices_offset)]
let mut chars = "a楽".char_indices();

assert_eq!(chars.offset(), 0);
assert_eq!(chars.next(), Some((0, 'a')));

assert_eq!(chars.offset(), 1);
assert_eq!(chars.next(), Some((1, '楽')));

assert_eq!(chars.offset(), 4);
assert_eq!(chars.next(), None);

相关用法


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