mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-04-28 18:27:55 +00:00
Some docs
This commit is contained in:
@@ -10,18 +10,27 @@ use std::cell::RefCell;
|
||||
use std::fmt::Display;
|
||||
use std::thread;
|
||||
|
||||
/// A type to collect errors together and format them.
|
||||
///
|
||||
/// Dropping this object will cause a panic. It must be consumed using `check`.
|
||||
///
|
||||
/// References can be shared since this type uses run-time exclusive mut checking.
|
||||
#[derive(Default)]
|
||||
pub struct Ctxt {
|
||||
// The contents will be set to `None` during checking. This is so that checking can be
|
||||
// enforced.
|
||||
errors: RefCell<Option<Vec<String>>>,
|
||||
}
|
||||
|
||||
impl Ctxt {
|
||||
/// Create a new context object
|
||||
pub fn new() -> Self {
|
||||
Ctxt {
|
||||
errors: RefCell::new(Some(Vec::new())),
|
||||
}
|
||||
}
|
||||
|
||||
/// Add an error to the context object
|
||||
pub fn error<T: Display>(&self, msg: T) {
|
||||
self.errors
|
||||
.borrow_mut()
|
||||
@@ -30,6 +39,7 @@ impl Ctxt {
|
||||
.push(msg.to_string());
|
||||
}
|
||||
|
||||
/// Consume this object, producing a formatted error string if there are errors.
|
||||
pub fn check(self) -> Result<(), String> {
|
||||
let mut errors = self.errors.borrow_mut().take().unwrap();
|
||||
match errors.len() {
|
||||
|
||||
Reference in New Issue
Block a user