From dbfb3d2ced91e56314dfabbb4df9a338926c0a7a Mon Sep 17 00:00:00 2001 From: Laurenz Date: Mon, 3 Aug 2020 16:01:23 +0200 Subject: =?UTF-8?q?Formatting,=20documentation=20and=20small=20improvement?= =?UTF-8?q?s=20=F0=9F=A7=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/main.rs | 43 +++++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 24 deletions(-) (limited to 'main') diff --git a/main/main.rs b/main/main.rs index a04b163c..0d67241c 100644 --- a/main/main.rs +++ b/main/main.rs @@ -1,44 +1,37 @@ use std::cell::RefCell; -use std::error::Error; -use std::fs::{File, read_to_string}; +use std::fs::{read_to_string, File}; use std::io::BufWriter; use std::path::{Path, PathBuf}; use std::rc::Rc; -use futures_executor::block_on; use fontdock::fs::{FsIndex, FsProvider}; use fontdock::FontLoader; -use typstc::Typesetter; -use typstc::font::DynProvider; +use futures_executor::block_on; + use typstc::export::pdf; +use typstc::font::DynProvider; +use typstc::Typesetter; fn main() { - if let Err(err) = run() { - eprintln!("error: {}", err); - std::process::exit(1); - } -} - -fn run() -> Result<(), Box> { - let args: Vec = std::env::args().collect(); + let args: Vec<_> = std::env::args().collect(); if args.len() < 2 || args.len() > 3 { println!("Usage: typst src.typ [out.pdf]"); - std::process::exit(0); + return; } - let source = Path::new(&args[1]); - let dest = if args.len() <= 2 { - source.with_extension("pdf") + let src_path = Path::new(&args[1]); + let dest_path = if args.len() <= 2 { + src_path.with_extension("pdf") } else { PathBuf::from(&args[2]) }; - if source == dest { - Err("source and destination path are the same")?; + if src_path == dest_path { + panic!("source and destination path are the same"); } - let src = read_to_string(source) - .map_err(|_| "failed to read from source file")?; + let src = read_to_string(src_path) + .expect("failed to read from source file"); let mut index = FsIndex::new(); index.search_dir("fonts"); @@ -53,8 +46,10 @@ fn run() -> Result<(), Box> { let typesetter = Typesetter::new(loader.clone()); let layouts = block_on(typesetter.typeset(&src)).output; - let writer = BufWriter::new(File::create(&dest)?); - pdf::export(&layouts, &loader, writer)?; + let file = File::create(&dest_path) + .expect("failed to create output file"); - Ok(()) + let writer = BufWriter::new(file); + pdf::export(&layouts, &loader, writer) + .expect("failed to export pdf"); } -- cgit v1.2.3