feat(export): update handler trait methods signature

This commit is contained in:
PoiScript 2019-11-05 19:56:07 +08:00
parent b8265814aa
commit 6483ef745f
2 changed files with 23 additions and 17 deletions

View file

@ -1,5 +1,5 @@
use std::fmt;
use std::io::{Error, Write};
use std::io::{Error, Result as IOResult, Write};
use jetscii::{bytes, BytesConst};
@ -50,7 +50,16 @@ impl<S: AsRef<str>> fmt::Display for HtmlEscape<S> {
}
pub trait HtmlHandler<E: From<Error>>: Default {
fn start<W: Write>(&mut self, mut w: W, element: &Element) -> Result<(), E> {
fn start<W: Write>(&mut self, w: W, element: &Element) -> Result<(), E>;
fn end<W: Write>(&mut self, w: W, element: &Element) -> Result<(), E>;
}
/// Default Html Handler
#[derive(Default)]
pub struct DefaultHtmlHandler;
impl HtmlHandler<Error> for DefaultHtmlHandler {
fn start<W: Write>(&mut self, mut w: W, element: &Element) -> IOResult<()> {
match element {
// container elements
Element::SpecialBlock(_) => (),
@ -195,7 +204,7 @@ pub trait HtmlHandler<E: From<Error>>: Default {
Ok(())
}
fn end<W: Write>(&mut self, mut w: W, element: &Element) -> Result<(), E> {
fn end<W: Write>(&mut self, mut w: W, element: &Element) -> IOResult<()> {
match element {
// container elements
Element::SpecialBlock(_) => (),
@ -241,12 +250,6 @@ pub trait HtmlHandler<E: From<Error>>: Default {
}
}
/// Default Html Handler
#[derive(Default)]
pub struct DefaultHtmlHandler;
impl HtmlHandler<Error> for DefaultHtmlHandler {}
#[cfg(feature = "syntect")]
mod syntect_handler {
use super::*;

View file

@ -1,10 +1,18 @@
use std::io::{Error, Write};
use std::io::{Error, Result as IOResult, Write};
use crate::elements::{Clock, Element, Table, Timestamp};
use crate::export::write_datetime;
pub trait OrgHandler<E: From<Error>>: Default {
fn start<W: Write>(&mut self, mut w: W, element: &Element) -> Result<(), E> {
fn start<W: Write>(&mut self, w: W, element: &Element) -> Result<(), E>;
fn end<W: Write>(&mut self, w: W, element: &Element) -> Result<(), E>;
}
#[derive(Default)]
pub struct DefaultOrgHandler;
impl OrgHandler<Error> for DefaultOrgHandler {
fn start<W: Write>(&mut self, mut w: W, element: &Element) -> IOResult<()> {
match element {
// container elements
Element::SpecialBlock(block) => {
@ -189,7 +197,7 @@ pub trait OrgHandler<E: From<Error>>: Default {
Ok(())
}
fn end<W: Write>(&mut self, mut w: W, element: &Element) -> Result<(), E> {
fn end<W: Write>(&mut self, mut w: W, element: &Element) -> IOResult<()> {
match element {
// container elements
Element::SpecialBlock(block) => {
@ -311,8 +319,3 @@ fn write_timestamp<W: Write>(mut w: W, timestamp: &Timestamp) -> Result<(), Erro
}
Ok(())
}
#[derive(Default)]
pub struct DefaultOrgHandler;
impl OrgHandler<Error> for DefaultOrgHandler {}