diff --git a/src/bin/main.rs b/src/bin/main.rs index f86336bbc..231ac4875 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -1,13 +1,13 @@ use std::fs::{File, read_to_string}; use std::io::BufWriter; use std::path::{Path, PathBuf}; - use futures_executor::block_on; use typstc::Typesetter; use typstc::toddle::query::FileSystemFontProvider; use typstc::export::pdf::PdfExporter; + fn main() { if let Err(err) = run() { eprintln!("error: {}", err); diff --git a/src/export/pdf.rs b/src/export/pdf.rs index c5bc6ee87..c4020e101 100644 --- a/src/export/pdf.rs +++ b/src/export/pdf.rs @@ -22,6 +22,7 @@ use toddle::tables::{ use crate::layout::{MultiLayout, Layout, LayoutAction}; use crate::size::Size; + /// Exports layouts into _PDFs_. pub struct PdfExporter {} diff --git a/src/func/macros.rs b/src/func/macros.rs index a89156b7f..bbe04b981 100644 --- a/src/func/macros.rs +++ b/src/func/macros.rs @@ -1,5 +1,6 @@ //! Helper types and macros for creating custom functions. + /// Defines function types concisely. #[macro_export] macro_rules! function { @@ -121,6 +122,7 @@ macro_rules! function { 'life1: 'async_trait, Self: 'async_trait, { + #[allow(unreachable_code)] Box::pin(async move { Ok($code) }) } } diff --git a/src/func/mod.rs b/src/func/mod.rs index a0875cf95..31f03c557 100644 --- a/src/func/mod.rs +++ b/src/func/mod.rs @@ -3,8 +3,8 @@ use std::any::Any; use std::collections::HashMap; use std::fmt::{self, Debug, Formatter}; - use async_trait::async_trait; + use self::prelude::*; #[macro_use] diff --git a/src/layout/actions.rs b/src/layout/actions.rs index 4ab9fdb1f..1bf5d6841 100644 --- a/src/layout/actions.rs +++ b/src/layout/actions.rs @@ -6,6 +6,7 @@ use toddle::query::FontIndex; use super::*; use LayoutAction::*; + /// A layouting action. #[derive(Clone)] pub enum LayoutAction { diff --git a/src/layout/line.rs b/src/layout/line.rs index 8f4873198..c4205e819 100644 --- a/src/layout/line.rs +++ b/src/layout/line.rs @@ -1,5 +1,6 @@ use super::*; + /// The line layouter arranges boxes next to each other along a primary axis /// and arranges the resulting lines using an underlying stack layouter. #[derive(Debug, Clone)] @@ -181,7 +182,7 @@ impl LineLayouter { /// Finish the run and add secondary spacing to the underlying stack. pub fn add_secondary_spacing( &mut self, - mut spacing: Size, + spacing: Size, kind: SpacingKind ) -> LayoutResult<()> { self.finish_line_if_not_empty()?; diff --git a/src/layout/mod.rs b/src/layout/mod.rs index be1ed43c9..495519451 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -39,6 +39,7 @@ pub use self::actions::{LayoutAction, LayoutActions}; pub use self::layouters::*; pub use self::prelude::*; + /// The result type for layouting. pub type LayoutResult = crate::TypesetResult; diff --git a/src/layout/stack.rs b/src/layout/stack.rs index e05626723..80d57424f 100644 --- a/src/layout/stack.rs +++ b/src/layout/stack.rs @@ -2,6 +2,7 @@ use smallvec::smallvec; use crate::size::ValueBox; use super::*; + /// The stack layouter stack boxes onto each other along the secondary layouting /// axis. #[derive(Debug, Clone)] diff --git a/src/layout/text.rs b/src/layout/text.rs index 2fdb3f6d2..a66e04a23 100644 --- a/src/layout/text.rs +++ b/src/layout/text.rs @@ -5,6 +5,7 @@ use crate::size::{Size, Size2D}; use crate::style::TextStyle; use super::*; + /// The context for text layouting. /// /// See [`LayoutContext`] for details about the fields. diff --git a/src/layout/tree.rs b/src/layout/tree.rs index f645a35d9..238c45fcf 100644 --- a/src/layout/tree.rs +++ b/src/layout/tree.rs @@ -4,7 +4,6 @@ use smallvec::smallvec; use crate::func::Command; use crate::syntax::{SyntaxTree, Node, FuncCall}; -use crate::style::TextStyle; use super::*; @@ -148,7 +147,7 @@ impl<'a, 'p> TreeLayouter<'a, 'p> { } SetAlignment(alignment) => self.ctx.alignment = alignment, SetAxes(axes) => { - self.layouter.set_axes(axes); + self.layouter.set_axes(axes)?; self.ctx.axes = axes; } } diff --git a/src/lib.rs b/src/lib.rs index 7975ff7d4..ffd464fe8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,7 +16,7 @@ //! format is _PDF_. Alternatively, the layout can be serialized to pass it to //! a suitable renderer. -#![allow(unused)] +// #![allow(unused)] pub extern crate toddle; @@ -42,6 +42,7 @@ pub mod syntax; pub mod size; pub mod style; + /// Transforms source code into typesetted layouts. /// /// A typesetter can be configured through various methods. diff --git a/src/library/maps/alignment.rs b/src/library/maps/alignment.rs index 486c8b2e8..8654e280a 100644 --- a/src/library/maps/alignment.rs +++ b/src/library/maps/alignment.rs @@ -1,6 +1,7 @@ use super::*; use AlignmentKey::*; + /// An argument key which describes a target alignment. #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] pub enum AlignmentKey { diff --git a/src/library/maps/axis.rs b/src/library/maps/axis.rs index ca306eab1..238d146a7 100644 --- a/src/library/maps/axis.rs +++ b/src/library/maps/axis.rs @@ -1,6 +1,7 @@ use super::*; use AxisKey::*; + /// An argument key which identifies a layouting axis. #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] pub enum AxisKey { diff --git a/src/library/maps/mod.rs b/src/library/maps/mod.rs index 5b027824c..5e130d53e 100644 --- a/src/library/maps/mod.rs +++ b/src/library/maps/mod.rs @@ -5,6 +5,7 @@ use std::hash::Hash; use crate::func::prelude::*; + macro_rules! key { ($type:ty, $name:expr, $($patterns:tt)*) => { impl $type { diff --git a/src/library/maps/padding.rs b/src/library/maps/padding.rs index 3da469a7f..4bbbb754f 100644 --- a/src/library/maps/padding.rs +++ b/src/library/maps/padding.rs @@ -3,6 +3,7 @@ use AxisKey::*; use AlignmentKey::*; use PaddingKey::*; + /// An argument key which identifies a margin or padding target. /// /// A is the used axis type. diff --git a/src/library/mod.rs b/src/library/mod.rs index 513590ebe..333ba02ad 100644 --- a/src/library/mod.rs +++ b/src/library/mod.rs @@ -58,7 +58,7 @@ function! { list: Vec, } - parse(args, body, ctx, meta) { + parse(args, body, ctx) { FontFamilyFunc { body: parse!(optional: body, ctx), list: { @@ -114,7 +114,7 @@ function! { weight: FontWeight, } - parse(args, body, ctx, meta) { + parse(args, body, ctx) { FontWeightFunc { body: parse!(optional: body, ctx), weight: match args.get_pos::()? { @@ -195,7 +195,7 @@ function! { } } - layout(self, mut ctx) { + layout(self, ctx) { let mut style = ctx.style.text.clone(); match self.content { ContentKind::Word => style.word_spacing_scale = self.spacing, diff --git a/src/macros.rs b/src/macros.rs index ebe1cad7a..5d4138701 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -1,5 +1,6 @@ //! Auxiliary macros. + /// Create trait implementations for an error type. macro_rules! error_type { ( @@ -36,16 +37,6 @@ macro_rules! error_type { }; } -/// Shorthand for checking whether an expression matches a pattern. -macro_rules! matches { - ($expr:expr, $($pattern:tt)*) => { - match $expr { - $($pattern)* => true, - _ => false, - } - }; -} - /// Create a `Debug` implementation from a `Display` implementation. macro_rules! debug_display { ($type:ident) => ( diff --git a/src/size.rs b/src/size.rs index 04eabf394..5b84c2ad8 100644 --- a/src/size.rs +++ b/src/size.rs @@ -7,6 +7,7 @@ use std::str::FromStr; use crate::layout::prelude::*; + /// A general spacing type. #[derive(Default, Copy, Clone, PartialEq, PartialOrd)] pub struct Size { diff --git a/src/syntax/mod.rs b/src/syntax/mod.rs index 193810c01..cb8016272 100644 --- a/src/syntax/mod.rs +++ b/src/syntax/mod.rs @@ -10,6 +10,7 @@ pub_use_mod!(tokens); pub_use_mod!(parsing); pub_use_mod!(span); + /// A logical unit of the incoming text stream. #[derive(Debug, Copy, Clone, Eq, PartialEq)] pub enum Token<'s> { diff --git a/src/syntax/parsing.rs b/src/syntax/parsing.rs index 6eed22356..2f061372a 100644 --- a/src/syntax/parsing.rs +++ b/src/syntax/parsing.rs @@ -4,6 +4,7 @@ use crate::func::Scope; use crate::size::Size; use super::*; + /// The result type for parsing. pub type ParseResult = crate::TypesetResult; diff --git a/src/syntax/span.rs b/src/syntax/span.rs index 9e0184374..3f752385e 100644 --- a/src/syntax/span.rs +++ b/src/syntax/span.rs @@ -2,6 +2,7 @@ use std::fmt::{self, Display, Formatter}; + /// Annotates a value with the part of the source code it corresponds to. #[derive(Copy, Clone, Eq, PartialEq)] pub struct Spanned { diff --git a/src/syntax/tokens.rs b/src/syntax/tokens.rs index 85e89be41..f5854d8f6 100644 --- a/src/syntax/tokens.rs +++ b/src/syntax/tokens.rs @@ -5,6 +5,7 @@ use smallvec::SmallVec; use super::*; + /// Builds an iterator over the tokens of the source code. pub fn tokenize(src: &str) -> Tokens { Tokens::new(src)