1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//! This module holds datastructures for the various `skip_*` methods of the
//! [`NoCommentIter`](::nocommentiter::NoCommentIter)
use std::fmt;

use lines::ParsedLine;

/// A struct returned by
/// [`skip_to_next_keyword`](::nocommentiter::NoCommentIter::skip_to_next_keyword).

/// A data structure returned by several skip methods on
/// [`NoCommentIter`](::nocommentiter::NoCommentIter)
///
/// `nextline` will be `None` in those cases where the iterator returned `None`
/// before such a line could be found, i.e. the file ended.
///
/// `skip_end` is the index of the last line we skipped. It will be `None` if
/// we could not fully skip something before the file ended
#[derive(Debug)]
pub struct SkipResult<'a> {
  pub nextline: Option<ParsedLine<'a>>,
  pub skip_end: Option<usize>,
}

impl<'a> Default for SkipResult<'a> {
  fn default() -> Self {
    SkipResult {
      nextline: None,
      skip_end: None,
    }
  }
}

impl<'a> fmt::Display for SkipResult<'a> {
  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
    if let Some(ref pl) = self.nextline {
      write!(
        f,
        "SkipResult {{ nextline: {}, skip_end: {:?} }}",
        pl, self.skip_end
      )
    } else {
      write!(
        f,
        "SkipResult {{ nextline: None, skip_end: {:?} }}",
        self.skip_end
      )
    }
  }
}