Skip to content

Commit

Permalink
allow State to borrow from events
Browse files Browse the repository at this point in the history
  • Loading branch information
max-heller committed Mar 16, 2024
1 parent 42739b5 commit b3bfd40
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
14 changes: 5 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ impl<'a> Options<'a> {
pub fn cmark_resume_with_options<'a, I, E, F>(
events: I,
mut formatter: F,
state: Option<State<'static>>,
state: Option<State<'a>>,
options: Options<'_>,
) -> Result<State<'static>, fmt::Error>
) -> Result<State<'a>, fmt::Error>
where
I: Iterator<Item = E>,
E: Borrow<Event<'a>>,
Expand Down Expand Up @@ -658,11 +658,7 @@ where
}

/// As [`cmark_resume_with_options()`], but with default [`Options`].
pub fn cmark_resume<'a, I, E, F>(
events: I,
formatter: F,
state: Option<State<'static>>,
) -> Result<State<'static>, fmt::Error>
pub fn cmark_resume<'a, I, E, F>(events: I, formatter: F, state: Option<State<'a>>) -> Result<State<'a>, fmt::Error>
where
I: Iterator<Item = E>,
E: Borrow<Event<'a>>,
Expand Down Expand Up @@ -741,7 +737,7 @@ pub fn cmark_with_options<'a, I, E, F>(
events: I,
mut formatter: F,
options: Options<'_>,
) -> Result<State<'static>, fmt::Error>
) -> Result<State<'a>, fmt::Error>
where
I: Iterator<Item = E>,
E: Borrow<Event<'a>>,
Expand All @@ -752,7 +748,7 @@ where
}

/// As [`cmark_with_options()`], but with default [`Options`].
pub fn cmark<'a, I, E, F>(events: I, mut formatter: F) -> Result<State<'static>, fmt::Error>
pub fn cmark<'a, I, E, F>(events: I, mut formatter: F) -> Result<State<'a>, fmt::Error>
where
I: Iterator<Item = E>,
E: Borrow<Event<'a>>,
Expand Down
8 changes: 4 additions & 4 deletions tests/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@ extern crate indoc;
use pulldown_cmark::{Alignment, CodeBlockKind, Event, LinkType, Options, Parser, Tag, TagEnd};
use pulldown_cmark_to_cmark::{cmark, cmark_resume, cmark_resume_with_options, Options as CmarkToCmarkOptions, State};

fn fmts(s: &str) -> (String, State<'static>) {
fn fmts(s: &str) -> (String, State<'_>) {
let mut buf = String::new();
let s = cmark(Parser::new_ext(s, Options::all()), &mut buf).unwrap();
(buf, s)
}

fn fmts_with_options(s: &str, options: CmarkToCmarkOptions) -> (String, State<'static>) {
fn fmts_with_options<'a>(s: &'a str, options: CmarkToCmarkOptions<'a>) -> (String, State<'a>) {
let mut buf = String::new();
let s = cmark_resume_with_options(Parser::new_ext(s, Options::all()), &mut buf, None, options).unwrap();
(buf, s)
}

fn fmtes(e: &[Event], s: State<'static>) -> (String, State<'static>) {
fn fmtes<'a>(e: &'a [Event], s: State<'a>) -> (String, State<'a>) {
let mut buf = String::new();
let s = cmark_resume(e.iter(), &mut buf, Some(s)).unwrap();
(buf, s)
}

fn fmte<'a>(e: impl AsRef<[Event<'a>]>) -> (String, State<'static>) {
fn fmte<'a>(e: impl AsRef<[Event<'a>]>) -> (String, State<'a>) {
let mut buf = String::new();
let s = cmark(e.as_ref().iter(), &mut buf).unwrap();
(buf, s)
Expand Down

0 comments on commit b3bfd40

Please sign in to comment.