aboutsummaryrefslogtreecommitdiffstats
path: root/document_tree/src
diff options
context:
space:
mode:
Diffstat (limited to 'document_tree/src')
-rw-r--r--document_tree/src/attribute_types.rs20
-rw-r--r--document_tree/src/element_categories.rs24
-rw-r--r--document_tree/src/elements.rs42
-rw-r--r--document_tree/src/lib.rs6
-rw-r--r--document_tree/src/url.rs2
5 files changed, 47 insertions, 47 deletions
diff --git a/document_tree/src/attribute_types.rs b/document_tree/src/attribute_types.rs
index 411b24d..ef00544 100644
--- a/document_tree/src/attribute_types.rs
+++ b/document_tree/src/attribute_types.rs
@@ -15,9 +15,13 @@ pub enum EnumeratedListType {
UpperRoman,
}
-#[derive(Debug,PartialEq,Eq,Hash,Serialize,Clone)]
-pub enum FixedSpace { Default, Preserve } // yes, default really is not “Default”
-impl Default for FixedSpace { fn default() -> FixedSpace { FixedSpace::Preserve } }
+#[derive(Default,Debug,PartialEq,Eq,Hash,Serialize,Clone)]
+pub enum FixedSpace {
+ Default,
+ // yes, default really is not “Default”
+ #[default]
+ Preserve,
+}
#[derive(Debug,PartialEq,Eq,Hash,Serialize,Clone)] pub enum AlignH { Left, Center, Right}
#[derive(Debug,PartialEq,Eq,Hash,Serialize,Clone)] pub enum AlignHV { Top, Middle, Bottom, Left, Center, Right }
@@ -32,12 +36,7 @@ impl Default for FixedSpace { fn default() -> FixedSpace { FixedSpace::Preserve
// The table DTD has the cols attribute of tgroup as required, but having
// TableGroupCols not implement Default would leave no possible implementation
// for TableGroup::with_children.
-#[derive(Debug,PartialEq,Eq,Hash,Serialize,Clone)] pub struct TableGroupCols(pub usize);
-impl Default for TableGroupCols {
- fn default() -> Self {
- TableGroupCols(0)
- }
-}
+#[derive(Default,Debug,PartialEq,Eq,Hash,Serialize,Clone)] pub struct TableGroupCols(pub usize);
// no eq for f64
#[derive(Debug,PartialEq,Serialize,Clone)]
@@ -104,7 +103,7 @@ impl FromStr for Measure {
#[cfg(test)]
mod parse_tests {
use super::*;
-
+
#[test]
fn measure() {
let _a: Measure = "1.5em".parse().unwrap();
@@ -152,4 +151,3 @@ impl CanBeEmpty for bool {
impl CanBeEmpty for FixedSpace {
fn is_empty(&self) -> bool { self == &FixedSpace::default() }
}
-
diff --git a/document_tree/src/element_categories.rs b/document_tree/src/element_categories.rs
index 24a0798..1f5fcde 100644
--- a/document_tree/src/element_categories.rs
+++ b/document_tree/src/element_categories.rs
@@ -25,9 +25,9 @@ macro_rules! impl_into {
$( impl_into!($subcat::$entry => $supcat); )+
};
($subcat:ident :: $entry:ident => $supcat:ident ) => {
- impl Into<$supcat> for $entry {
- fn into(self) -> $supcat {
- $supcat::$subcat(Box::new(self.into()))
+ impl From<$entry> for $supcat {
+ fn from(inner: $entry) -> Self {
+ $supcat::$subcat(Box::new(inner.into()))
}
}
};
@@ -47,7 +47,7 @@ macro_rules! synonymous_enum {
pub enum $name { $(
$entry(Box<$entry>),
)* }
-
+
impl Debug for $name {
fn fmt(&self, fmt: &mut Formatter) -> Result<(), fmt::Error> {
match *self {
@@ -55,10 +55,10 @@ macro_rules! synonymous_enum {
}
}
}
-
- $( impl Into<$name> for $entry {
- fn into(self) -> $name {
- $name::$entry(Box::new(self))
+
+ $( impl From<$entry> for $name {
+ fn from(inner: $entry) -> Self {
+ $name::$entry(Box::new(inner))
}
} )*
};
@@ -106,22 +106,22 @@ synonymous_enum!(SubTableGroup { TableColspec, TableHead, TableBody });
mod conversion_tests {
use std::default::Default;
use super::*;
-
+
#[test]
fn basic() {
let _: BodyElement = Paragraph::default().into();
}
-
+
#[test]
fn more() {
let _: SubStructure = Paragraph::default().into();
}
-
+
#[test]
fn even_more() {
let _: StructuralSubElement = Paragraph::default().into();
}
-
+
#[test]
fn super_() {
let be: BodyElement = Paragraph::default().into();
diff --git a/document_tree/src/elements.rs b/document_tree/src/elements.rs
index 1db0a24..e32c677 100644
--- a/document_tree/src/elements.rs
+++ b/document_tree/src/elements.rs
@@ -59,7 +59,7 @@ macro_rules! impl_element { ($name:ident) => (
macro_rules! impl_children { ($name:ident, $childtype:ident) => (
impl HasChildren<$childtype> for $name {
#[allow(clippy::needless_update)]
- fn with_children(children: Vec<$childtype>) -> $name { $name { children: children, ..Default::default() } }
+ fn with_children(children: Vec<$childtype>) -> $name { $name { children, ..Default::default() } }
fn children (& self) -> & Vec<$childtype> { & self.children }
fn children_mut(&mut self) -> &mut Vec<$childtype> { &mut self.children }
}
@@ -68,7 +68,7 @@ macro_rules! impl_children { ($name:ident, $childtype:ident) => (
macro_rules! impl_extra { ($name:ident $($more:tt)*) => (
impl ExtraAttributes<extra_attributes::$name> for $name {
#[allow(clippy::needless_update)]
- fn with_extra(extra: extra_attributes::$name) -> $name { $name { common: Default::default(), extra: extra $($more)* } }
+ fn with_extra(extra: extra_attributes::$name) -> $name { $name { common: Default::default(), extra $($more)* } }
fn extra (& self) -> & extra_attributes::$name { & self.extra }
fn extra_mut(&mut self) -> &mut extra_attributes::$name { &mut self.extra }
}
@@ -82,7 +82,7 @@ impl<T, C, A> HasExtraAndChildren<C, A> for T where T: HasChildren<C> + ExtraAtt
#[allow(clippy::needless_update)]
fn with_extra_and_children(extra: A, mut children: Vec<C>) -> Self {
let mut r = Self::with_extra(extra);
- r.children_mut().extend(children.drain(..));
+ r.children_mut().append(&mut children);
r
}
}
@@ -96,11 +96,11 @@ macro_rules! impl_new {(
) => (
$(#[$attr])*
#[derive(Debug,PartialEq,Serialize,Clone)]
- pub struct $name { $(
+ pub struct $name { $(
$(#[$fattr])* $field: $typ,
)* }
impl $name {
- pub fn new( $( $field: $typ, )* ) -> $name { $name { $( $field: $field, )* } }
+ pub fn new( $( $field: $typ, )* ) -> $name { $name { $( $field, )* } }
}
)}
@@ -156,14 +156,14 @@ impl_elems!(
(Section, StructuralSubElement)
(Topic, SubTopic)
(Sidebar, SubSidebar)
-
+
//structural subelements
(Title, TextOrInlineElement)
(Subtitle, TextOrInlineElement)
(Decoration, DecorationElement)
(Docinfo, BibliographicElement)
(Transition)
-
+
//bibliographic elements
(Author, TextOrInlineElement)
(Authors, AuthorInfo)
@@ -176,11 +176,11 @@ impl_elems!(
(Date, TextOrInlineElement)
(Copyright, TextOrInlineElement)
(Field, SubField)
-
+
//decoration elements
(Header, BodyElement)
(Footer, BodyElement)
-
+
//simple body elements
(Paragraph, TextOrInlineElement)
(LiteralBlock, TextOrInlineElement; +)
@@ -193,17 +193,17 @@ impl_elems!(
(Target; +)
(Raw, String; +)
(Image; *)
-
+
//compound body elements
(Compound, BodyElement)
(Container, BodyElement)
-
+
(BulletList, ListItem; +)
(EnumeratedList, ListItem; +)
(DefinitionList, DefinitionListItem)
(FieldList, Field)
(OptionList, OptionListItem)
-
+
(LineBlock, SubLineBlock)
(BlockQuote, SubBlockQuote)
(Admonition, SubTopic)
@@ -229,32 +229,32 @@ impl_elems!(
(TableRow, TableEntry; +)
(TableEntry, BodyElement; +)
(TableColspec; +)
-
+
//body sub elements
(ListItem, BodyElement)
-
+
(DefinitionListItem, SubDLItem)
(Term, TextOrInlineElement)
(Classifier, TextOrInlineElement)
(Definition, BodyElement)
-
+
(FieldName, TextOrInlineElement)
(FieldBody, BodyElement)
-
+
(OptionListItem, SubOptionListItem)
(OptionGroup, Option_)
(Description, BodyElement)
(Option_, SubOption)
(OptionString, String)
(OptionArgument, String; +)
-
+
(Line, TextOrInlineElement)
(Attribution, TextOrInlineElement)
(Label, TextOrInlineElement)
-
+
(Caption, TextOrInlineElement)
(Legend, BodyElement)
-
+
//inline elements
(Emphasis, TextOrInlineElement)
(Literal, String)
@@ -272,12 +272,12 @@ impl_elems!(
(Problematic, TextOrInlineElement; +)
(Generated, TextOrInlineElement)
(Math, String)
-
+
//also have non-inline versions. Inline image is no figure child, inline target has content
(TargetInline, String; +)
(RawInline, String; +)
(ImageInline; *)
-
+
//text element = String
);
diff --git a/document_tree/src/lib.rs b/document_tree/src/lib.rs
index 9154725..00d6cb2 100644
--- a/document_tree/src/lib.rs
+++ b/document_tree/src/lib.rs
@@ -1,7 +1,9 @@
#![recursion_limit="256"]
-///http://docutils.sourceforge.net/docs/ref/doctree.html
-///serves as AST
+/// See [doctree][] reference.
+/// Serves as AST.
+///
+/// [doctree]: http://docutils.sourceforge.net/docs/ref/doctree.html
#[macro_use]
mod macro_util;
diff --git a/document_tree/src/url.rs b/document_tree/src/url.rs
index 31a0536..543f9e5 100644
--- a/document_tree/src/url.rs
+++ b/document_tree/src/url.rs
@@ -57,7 +57,7 @@ impl Url {
impl From<url::Url> for Url {
fn from(url: url::Url) -> Self {
- Url(url.into_string())
+ Url(url.into())
}
}