如何解决通过示例了解 Rust Components 迭代器的绝对和相对路径
从 here 我了解到 components
方法在 Components
的 std::path::Path
上生成迭代器。特别地,Components
类型定义为:
pub struct Components<'a> {
// The path left to parse components from
path: &'a [u8],// The prefix as it was originally parsed,if any
prefix: Option<Prefix<'a>>,// true if path *physically* has a root separator; for most Windows
// prefixes,it may have a "logical" rootseparator for the purposes of
// normalization,e.g.,\\server\share == \\server\share\.
has_physical_root: bool,// The iterator is double-ended,and these two states keep track of what has
// been produced from either end
front: State,back: State,}
因此,
pub fn components(&self) -> Components<'_> {
let prefix = parse_prefix(self.as_os_str());
Components {
path: self.as_u8_slice(),prefix,has_physical_root: has_physical_root(self.as_u8_slice(),prefix)
|| has_redox_scheme(self.as_u8_slice()),front: State::Prefix,back: State::Body,}
}
然而,我仍然难以理解正在运行的迭代器。如果有人能解释(最好用一个例子)Components
成员在每次调用绝对和/或相对路径的 next
方法后持有什么,我将不胜感激。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。