Lines Matching defs:cursor
58 //! let mut cursor = raw.cursor();
59 //! raw.next(&mut cursor); // Skip the bin
60 //! while let Some(arg) = raw.next(&mut cursor) {
62 //! args.paths.extend(raw.remaining(&mut cursor).map(PathBuf::from));
136 /// let mut cursor = raw.cursor();
137 /// let _bin = raw.next_os(&mut cursor);
139 /// let mut paths = raw.remaining(&mut cursor).map(PathBuf::from).collect::<Vec<_>>();
153 /// let mut cursor = raw.cursor();
154 /// let _bin = raw.next_os(&mut cursor);
156 /// let mut paths = raw.remaining(&mut cursor).map(PathBuf::from).collect::<Vec<_>>();
164 /// Create a cursor for walking the arguments
171 /// let mut cursor = raw.cursor();
172 /// let _bin = raw.next_os(&mut cursor);
174 /// let mut paths = raw.remaining(&mut cursor).map(PathBuf::from).collect::<Vec<_>>();
177 pub fn cursor(&self) -> ArgCursor {
181 /// Advance the cursor, returning the next [`ParsedArg`]
182 pub fn next(&self, cursor: &mut ArgCursor) -> Option<ParsedArg<'_>> {
183 self.next_os(cursor).map(ParsedArg::new)
186 /// Advance the cursor, returning a raw argument value.
187 pub fn next_os(&self, cursor: &mut ArgCursor) -> Option<&OsStr> {
188 let next = self.items.get(cursor.cursor).map(|s| s.as_os_str());
189 cursor.cursor = cursor.cursor.saturating_add(1);
194 pub fn peek(&self, cursor: &ArgCursor) -> Option<ParsedArg<'_>> {
195 self.peek_os(cursor).map(ParsedArg::new)
199 pub fn peek_os(&self, cursor: &ArgCursor) -> Option<&OsStr> {
200 self.items.get(cursor.cursor).map(|s| s.as_os_str())
203 /// Return all remaining raw arguments, advancing the cursor to the end
210 /// let mut cursor = raw.cursor();
211 /// let _bin = raw.next_os(&mut cursor);
213 /// let mut paths = raw.remaining(&mut cursor).map(PathBuf::from).collect::<Vec<_>>();
216 pub fn remaining(&self, cursor: &mut ArgCursor) -> impl Iterator<Item = &OsStr> {
217 let remaining = self.items[cursor.cursor..].iter().map(|s| s.as_os_str());
218 cursor.cursor = self.items.len();
222 /// Adjust the cursor's position
223 pub fn seek(&self, cursor: &mut ArgCursor, pos: SeekFrom) {
227 SeekFrom::Current(pos) => (cursor.cursor as i64).saturating_add(pos).max(0) as u64,
230 cursor.cursor = pos;
236 cursor: &ArgCursor,
240 cursor.cursor..cursor.cursor,
246 pub fn is_end(&self, cursor: &ArgCursor) -> bool {
247 self.peek_os(cursor).is_none()
266 cursor: usize,
271 Self { cursor: 0 }