Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Commit

Permalink
Drop requirements for resource handler impls
Browse files Browse the repository at this point in the history
Do not require that these impls be send, sync or debug.
  • Loading branch information
swsnr committed Nov 24, 2024
1 parent 70ccb76 commit 65159b8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 21 deletions.
3 changes: 1 addition & 2 deletions pulldown-cmark-mdcat/src/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl MimeData {
///
/// For remote URLs, see e.g. [mdcat-http-reqwest](https://docs.rs/mdcat-http-reqwest)
/// for an implementation which fetches HTTP resources with the `reqwest` library.
pub trait ResourceUrlHandler: Send + Sync + Debug {
pub trait ResourceUrlHandler {
/// Read a resource.
///
/// Read data from the given `url`, and return the data and its associated mime type if known,
Expand Down Expand Up @@ -80,7 +80,6 @@ pub fn filter_schemes<'a>(schemes: &[&str], url: &'a Url) -> Result<&'a Url> {
}

/// A resource handler which dispatches reading among a list of inner handlers.
#[derive(Debug)]
pub struct DispatchingResourceHandler {
/// Inner handlers.
handlers: Vec<Box<dyn ResourceUrlHandler>>,
Expand Down
2 changes: 1 addition & 1 deletion pulldown-cmark-mdcat/src/terminal/capabilities/iterm2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl ITerm2Protocol {
/// supported by macOS, this may yield false positives, i.e. this implementation might not return
/// an error even though iTerm2 cannot actually display the image.
impl InlineImageProtocol for ITerm2Protocol {
#[instrument(skip(self, writer, _terminal_size), fields(url = %url))]
#[instrument(skip(self, writer, _terminal_size, resource_handler), fields(url = %url))]
fn write_inline_image(
&self,
writer: &mut dyn Write,
Expand Down
2 changes: 1 addition & 1 deletion pulldown-cmark-mdcat/src/terminal/capabilities/kitty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ impl KittyGraphicsProtocol {
/// See <https://sw.kovidgoyal.net/kitty/graphics-protocol.html#control-data-reference>
/// for reference.
impl InlineImageProtocol for KittyGraphicsProtocol {
#[instrument(skip(self, writer, terminal_size))]
#[instrument(skip(self, writer, resource_handler, terminal_size))]
fn write_inline_image(
&self,
writer: &mut dyn Write,
Expand Down
30 changes: 13 additions & 17 deletions pulldown-cmark-mdcat/tests/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,18 @@ fn syntax_set() -> &'static SyntaxSet {
SYNTAX_SET.get_or_init(SyntaxSet::load_defaults_newlines)
}

static RESOURCE_HANDLER: OnceLock<DispatchingResourceHandler> = OnceLock::new();

fn resource_handler() -> &'static DispatchingResourceHandler {
RESOURCE_HANDLER.get_or_init(|| {
let handlers: Vec<Box<dyn ResourceUrlHandler>> = vec![
Box::new(FileResourceHandler::new(TEST_READ_LIMIT)),
Box::new(
HttpResourceHandler::with_user_agent(
TEST_READ_LIMIT,
concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION")),
)
.unwrap(),
),
];
DispatchingResourceHandler::new(handlers)
})
fn resource_handler() -> DispatchingResourceHandler {
let handlers: Vec<Box<dyn ResourceUrlHandler>> = vec![
Box::new(FileResourceHandler::new(TEST_READ_LIMIT)),
Box::new(
HttpResourceHandler::with_user_agent(
TEST_READ_LIMIT,
concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION")),
)
.unwrap(),
),
];
DispatchingResourceHandler::new(handlers)
}

fn render_to_string<P: AsRef<Path>>(markdown_file: P, settings: &Settings) -> String {
Expand All @@ -66,7 +62,7 @@ fn render_to_string<P: AsRef<Path>>(markdown_file: P, settings: &Settings) -> St
hostname: "HOSTNAME".to_string(),
..Environment::for_local_directory(&base_dir).unwrap()
};
pulldown_cmark_mdcat::push_tty(settings, &env, resource_handler(), &mut sink, parser).unwrap();
pulldown_cmark_mdcat::push_tty(settings, &env, &resource_handler(), &mut sink, parser).unwrap();
String::from_utf8(sink).unwrap()
}

Expand Down

0 comments on commit 65159b8

Please sign in to comment.