Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
14bbbe9
Capture docs for types, fields, and enum variants
ascjones Apr 26, 2021
4e696dc
Add docs to derive tests
ascjones Apr 26, 2021
55fc739
Fmt
ascjones Apr 26, 2021
ded2f3f
Fmt
ascjones Apr 27, 2021
3b78d47
Make clippy happy
ascjones Apr 27, 2021
c74422d
Fix struct docs tests
ascjones Apr 27, 2021
329d915
Fix struct docs tests
ascjones Apr 27, 2021
637ab5a
Add missing Vec import
ascjones Apr 27, 2021
efdd3e4
Fix test
ascjones Apr 27, 2021
77fc88a
Clear docs
ascjones Apr 27, 2021
912fbcb
Merge branch 'master' into aj-docs
ascjones May 25, 2021
4151589
Promote build to it's own mod, split fields and variant builders
ascjones May 25, 2021
a0743b0
Refactor variant construction with builder
ascjones May 25, 2021
fd6f893
Fix up derive and unit tests with Variant builder
ascjones May 25, 2021
52f5e83
Fmt
ascjones May 25, 2021
2d2ab5c
Condense build module back to single file
ascjones May 25, 2021
c4bf49d
Fix up doc tests
ascjones May 25, 2021
05d875b
Fix up README
ascjones May 25, 2021
790a6b8
Define initial field builder
ascjones May 26, 2021
0f3b795
Fix up field building
ascjones May 26, 2021
655279a
Fix tests
ascjones May 26, 2021
63b986a
Fully qualify calls to stringify
ascjones May 26, 2021
150ef4e
Default impl for FieldBuilder
ascjones May 26, 2021
43551f4
Fix up default impl
ascjones May 26, 2021
0decd01
Fix spelling errors
ascjones May 26, 2021
e031939
Remove clear_docs
ascjones May 26, 2021
fdd96c3
Fully qualify module_path
ascjones May 26, 2021
585a671
Update derive/src/lib.rs
ascjones May 26, 2021
a7179b5
Merge remote-tracking branch 'origin/aj-docs' into aj-docs
ascjones May 26, 2021
4d73ae4
Use callback for variant builder
ascjones May 26, 2021
59ff44c
Update README
ascjones May 26, 2021
e8ea40b
Remove leading space in doc comments
ascjones May 26, 2021
1c01b94
Satisfy clippy
ascjones May 26, 2021
0edec05
Add test for doc capture
ascjones May 27, 2021
fcc8985
Rename index back to discriminant, changes for this will be in https:…
ascjones May 27, 2021
6fb8042
Rename index back to discriminant, changes for this will be in https:…
ascjones May 27, 2021
882bdb4
Update src/build.rs
ascjones May 27, 2021
ebc3e4b
Update src/build.rs
ascjones May 27, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove clear_docs
  • Loading branch information
ascjones committed May 26, 2021
commit e031939e23a69b5a27e6cf158c7e841e93296ebf
145 changes: 1 addition & 144 deletions src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,27 +188,14 @@ impl PortableRegistry {
(id, ty)
})
}

/// Clears all docs from types.
///
/// Use when the docs are not required to produce smaller encoded metadata.
pub fn clear_docs(&mut self) {
for ty in &mut self.types {
ty.clear_docs()
}
}
}

#[cfg(test)]
mod tests {
use super::*;
use crate::{
build::{
Fields,
Variants,
},
build::Fields,
meta_type,
ty::Variant,
Path,
TypeDef,
TypeInfo,
Expand Down Expand Up @@ -280,134 +267,4 @@ mod tests {
panic!("Should be a composite type definition")
}
}

#[test]
fn clear_docs() {
#[allow(unused)]
/// docs
struct S {
/// docs
pub t: bool,
pub u: u8,
}

impl TypeInfo for S {
type Identity = Self;

fn type_info() -> Type {
Type::builder()
.path(Path::new("S", module_path!()))
.docs(&[" docs"])
.composite(
Fields::named()
.field(|f| {
f.ty::<bool>()
.name("t")
.type_name("bool")
.docs(&[" docs"])
})
.field(|f| f.ty::<u8>().name("u").type_name("u8")),
)
}
}

#[allow(unused)]
struct T(
/// docs
u32,
);

impl TypeInfo for T {
type Identity = Self;

fn type_info() -> Type {
Type::builder()
.path(Path::new("T", module_path!()))
.docs(&[" docs"])
.composite(
Fields::unnamed()
.field(|f| f.ty::<u32>().type_name("u32").docs(&[" docs"])),
)
}
}

#[allow(unused)]
/// docs
enum E {
/// docs
A(
/// docs
bool,
),
/// docs
B {
/// docs
b: u8,
},
/// docs
C,
}

impl TypeInfo for E {
type Identity = Self;

fn type_info() -> Type {
Type::builder()
.path(Path::new("E", "derive"))
.type_params(tuple_meta_type!(bool))
.docs(&[" Enum docs."])
.variant(
Variants::new()
.variant(
Variant::builder("A")
.fields(Fields::unnamed().field(|f| {
f.ty::<bool>().type_name("bool").docs(&[" docs"])
}))
.docs(&[" Unnamed fields variant."]),
)
.variant(
Variant::builder("B")
.fields(Fields::named().field(|f| {
f.ty::<u8>()
.name("b")
.type_name("u8")
.docs(&[" docs"])
}))
.docs(&[" docs"]),
)
.variant(Variant::builder("C").docs(&[" docs"])),
)
}
}

let mut registry = Registry::new();
registry.register_type(&meta_type::<S>());
registry.register_type(&meta_type::<T>());
registry.register_type(&meta_type::<E>());

let mut registry: PortableRegistry = registry.into();

registry.clear_docs();

for ty in registry.types {
assert!(ty.docs().is_empty());
match ty.type_def() {
TypeDef::Composite(c) => {
for f in c.fields() {
assert!(f.docs().is_empty())
}
}
TypeDef::Variant(v) => {
for var in v.variants() {
assert!(var.docs().is_empty());

for f in var.fields() {
assert!(f.docs().is_empty())
}
}
}
_ => {}
}
}
}
}
7 changes: 0 additions & 7 deletions src/ty/composite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,4 @@ where
pub fn fields(&self) -> &[Field<T>] {
&self.fields
}

/// Clear the docs of the field.
pub fn clear_docs(&mut self) {
for field in &mut self.fields {
field.clear_docs()
}
}
}
5 changes: 0 additions & 5 deletions src/ty/fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,4 @@ where
pub fn docs(&self) -> &[T::String] {
&self.docs
}

/// Clear the docs of the field.
pub fn clear_docs(&mut self) {
self.docs.clear()
}
}
17 changes: 0 additions & 17 deletions src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,6 @@ pub struct Type<T: Form = MetaForm> {
docs: Vec<T::String>,
}

impl Type<PortableForm> {
/// Clear docs from this type.
pub fn clear_docs(&mut self) {
self.docs.clear();
match &mut self.type_def {
TypeDef::Composite(composite) => composite.clear_docs(),
TypeDef::Variant(variant) => variant.clear_docs(),
TypeDef::Sequence(_) => {}
TypeDef::Array(_) => {}
TypeDef::Tuple(_) => {}
TypeDef::Primitive(_) => {}
TypeDef::Compact(_) => {}
TypeDef::Phantom(_) => {}
}
}
}

impl IntoPortable for Type {
type Output = Type<PortableForm>;

Expand Down
15 changes: 0 additions & 15 deletions src/ty/variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,6 @@ where
pub fn variants(&self) -> &[Variant<T>] {
&self.variants
}

/// Clear docs for all variants.
pub fn clear_docs(&mut self) {
for variant in &mut self.variants {
variant.clear_docs()
}
}
}

/// A struct enum variant with either named (struct) or unnamed (tuple struct)
Expand Down Expand Up @@ -244,12 +237,4 @@ where
pub fn docs(&self) -> &[T::String] {
&self.docs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe doc should be an Option. Feels a bit more rusty to check for None rather than an empty slice?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer an empty slice, it conveys the same meaning and is easier to consume.

}

/// Clear the docs for this variant.
pub fn clear_docs(&mut self) {
self.docs.clear();
for field in &mut self.fields {
field.clear_docs()
}
}
}