Make the recommended changed from code review.

This commit is contained in:
Richard Dodd 2018-09-30 12:34:52 +01:00
parent da65fe5a52
commit f1073dca04
3 changed files with 9 additions and 7 deletions

View File

@ -6,7 +6,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
//! A serde ast, parsed from the syn ast and ready for codegen. //! A serde ast, parsed from the syn ast and ready to generate rust code.
use internals::attr; use internals::attr;
use internals::check; use internals::check;
@ -14,7 +14,7 @@ use internals::{Ctxt, Derive};
use syn; use syn;
use syn::punctuated::Punctuated; use syn::punctuated::Punctuated;
/// A source data structure annotated with `#[derive(Derialize)]` and/or `#[derive(Deserialize)]`, /// A source data structure annotated with `#[derive(Serialize)]` and/or `#[derive(Deserialize)]`,
/// parsed into an internal representation. /// parsed into an internal representation.
pub struct Container<'a> { pub struct Container<'a> {
/// The struct or enum name (without generics). /// The struct or enum name (without generics).
@ -43,7 +43,7 @@ pub struct Variant<'a> {
pub fields: Vec<Field<'a>>, pub fields: Vec<Field<'a>>,
} }
/// A variant of a struct. /// A field of a struct.
pub struct Field<'a> { pub struct Field<'a> {
pub member: syn::Member, pub member: syn::Member,
pub attrs: attr::Field, pub attrs: attr::Field,

View File

@ -6,8 +6,8 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
//! Stuff to handle where the case of the source (e.g. `my-field`) is different to the //! Utility code to assist converting the case of the source (e.g. `my-field`, `MY_FIELD`) to the
//! field/variant (e.g. `my_field`). //! rust-styled field/variant (e.g. `my_field`, `MyType`).
// See https://users.rust-lang.org/t/psa-dealing-with-warning-unused-import-std-ascii-asciiext-in-today-s-nightly/13726 // See https://users.rust-lang.org/t/psa-dealing-with-warning-unused-import-std-ascii-asciiext-in-today-s-nightly/13726
#[allow(deprecated, unused_imports)] #[allow(deprecated, unused_imports)]

View File

@ -23,14 +23,16 @@ pub struct Ctxt {
} }
impl Ctxt { impl Ctxt {
/// Create a new context object /// Create a new context object.
///
/// This object contains no errors, but will still trigger a panic if it is not `check`ed.
pub fn new() -> Self { pub fn new() -> Self {
Ctxt { Ctxt {
errors: RefCell::new(Some(Vec::new())), errors: RefCell::new(Some(Vec::new())),
} }
} }
/// Add an error to the context object /// Add an error to the context object.
pub fn error<T: Display>(&self, msg: T) { pub fn error<T: Display>(&self, msg: T) {
self.errors self.errors
.borrow_mut() .borrow_mut()