1 // Copyright 2017 Serde Developers
3 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6 // option. This file may not be copied, modified, or distributed
7 // except according to those terms.
10 use std
::cell
::RefCell
;
14 errors
: RefCell
<Option
<Vec
<String
>>>,
18 pub fn new() -> Self {
19 Ctxt { errors: RefCell::new(Some(Vec::new())) }
22 pub fn error
<T
: Display
>(&self, msg
: T
) {
27 .push(msg
.to_string());
30 pub fn check(self) -> Result
<(), String
> {
31 let mut errors
= self.errors
.borrow_mut().take().unwrap();
34 1 => Err(errors
.pop().unwrap()),
36 let mut msg
= format
!("{} errors:", n
);
38 msg
.push_str("\n\t# ");
49 if self.errors
.borrow().is_some() {
50 panic
!("forgot to check for errors");