pub struct State<'a> {
pub s: pp::Printer<'a>,
cm: Option<&'a SourceMap>,
- comments: Option<Vec<comments::Comment>>,
+ comments: Vec<comments::Comment>,
cur_cmnt: usize,
ann: &'a (dyn PpAnn + 'a),
}
&mut self.s
}
- fn comments(&mut self) -> &mut Option<Vec<comments::Comment>> {
+ fn comments(&mut self) -> &mut Vec<comments::Comment> {
&mut self.comments
}
State {
s: pp::mk_printer(out),
cm: Some(cm),
- comments,
+ comments: comments.unwrap_or_default(),
cur_cmnt: 0,
ann,
}
let mut printer = State {
s: pp::mk_printer(&mut wr),
cm: None,
- comments: None,
+ comments: Vec::new(),
cur_cmnt: 0,
ann,
};
pub struct State<'a> {
pub s: pp::Printer<'a>,
cm: Option<&'a SourceMap>,
- comments: Option<Vec<comments::Comment>>,
+ comments: Vec<comments::Comment>,
cur_cmnt: usize,
ann: &'a (dyn PpAnn+'a),
is_expanded: bool
State {
s: pp::mk_printer(out),
cm: Some(cm),
- comments,
+ comments: comments.unwrap_or_default(),
cur_cmnt: 0,
ann,
is_expanded,
let mut printer = State {
s: pp::mk_printer(&mut wr),
cm: None,
- comments: None,
+ comments: Vec::new(),
cur_cmnt: 0,
ann: &NoAnn,
is_expanded: false
pub trait PrintState<'a> {
fn writer(&mut self) -> &mut pp::Printer<'a>;
- fn comments(&mut self) -> &mut Option<Vec<comments::Comment>>;
+ fn comments(&mut self) -> &mut Vec<comments::Comment>;
fn cur_cmnt(&mut self) -> &mut usize;
fn word_space<S: Into<Cow<'static, str>>>(&mut self, w: S) {
fn next_comment(&mut self) -> Option<comments::Comment> {
let cur_cmnt = *self.cur_cmnt();
- match *self.comments() {
- Some(ref cmnts) => {
- if cur_cmnt < cmnts.len() {
- Some(cmnts[cur_cmnt].clone())
- } else {
- None
- }
- }
- _ => None
+ let cmnts = &*self.comments();
+ if cur_cmnt < cmnts.len() {
+ Some(cmnts[cur_cmnt].clone())
+ } else {
+ None
}
}
&mut self.s
}
- fn comments(&mut self) -> &mut Option<Vec<comments::Comment>> {
+ fn comments(&mut self) -> &mut Vec<comments::Comment> {
&mut self.comments
}