Make the recommended changed from code review.
This commit is contained in:
parent
da65fe5a52
commit
f1073dca04
@ -6,7 +6,7 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// 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::check;
|
||||
@ -14,7 +14,7 @@ use internals::{Ctxt, Derive};
|
||||
use syn;
|
||||
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.
|
||||
pub struct Container<'a> {
|
||||
/// The struct or enum name (without generics).
|
||||
@ -43,7 +43,7 @@ pub struct Variant<'a> {
|
||||
pub fields: Vec<Field<'a>>,
|
||||
}
|
||||
|
||||
/// A variant of a struct.
|
||||
/// A field of a struct.
|
||||
pub struct Field<'a> {
|
||||
pub member: syn::Member,
|
||||
pub attrs: attr::Field,
|
||||
|
@ -6,8 +6,8 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
//! Stuff to handle where the case of the source (e.g. `my-field`) is different to the
|
||||
//! field/variant (e.g. `my_field`).
|
||||
//! Utility code to assist converting the case of the source (e.g. `my-field`, `MY_FIELD`) to the
|
||||
//! 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
|
||||
#[allow(deprecated, unused_imports)]
|
||||
|
@ -23,14 +23,16 @@ pub struct 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 {
|
||||
Ctxt {
|
||||
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) {
|
||||
self.errors
|
||||
.borrow_mut()
|
||||
|
Loading…
x
Reference in New Issue
Block a user