Skip to content

Commit

Permalink
Allow non-Send StreamingHandler to exist
Browse files Browse the repository at this point in the history
  • Loading branch information
kornelski authored and orium committed Nov 29, 2024
1 parent e898cc5 commit 9a124eb
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 23 deletions.
12 changes: 6 additions & 6 deletions src/rewritable_units/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ impl<'r, 't, H: HandlerTypes> Element<'r, 't, H> {
/// Consequent calls to the method append to the previously inserted content.
///
/// Use the [`streaming!`] macro to make a `StreamingHandler` from a closure.
pub fn streaming_before(&mut self, string_writer: Box<dyn StreamingHandler>) {
pub fn streaming_before(&mut self, string_writer: Box<dyn StreamingHandler + Send>) {
self.start_tag
.mutations
.mutate()
Expand Down Expand Up @@ -305,7 +305,7 @@ impl<'r, 't, H: HandlerTypes> Element<'r, 't, H> {
///
///
/// Use the [`streaming!`] macro to make a `StreamingHandler` from a closure.
pub fn streaming_after(&mut self, string_writer: Box<dyn StreamingHandler>) {
pub fn streaming_after(&mut self, string_writer: Box<dyn StreamingHandler + Send>) {
self.after_chunk(StringChunk::Stream(string_writer));
}

Expand Down Expand Up @@ -369,7 +369,7 @@ impl<'r, 't, H: HandlerTypes> Element<'r, 't, H> {
///
///
/// Use the [`streaming!`] macro to make a `StreamingHandler` from a closure.
pub fn streaming_prepend(&mut self, string_writer: Box<dyn StreamingHandler>) {
pub fn streaming_prepend(&mut self, string_writer: Box<dyn StreamingHandler + Send>) {
self.prepend_chunk(StringChunk::Stream(string_writer));
}

Expand Down Expand Up @@ -428,7 +428,7 @@ impl<'r, 't, H: HandlerTypes> Element<'r, 't, H> {
/// [empty element]: https://developer.mozilla.org/en-US/docs/Glossary/Empty_element
///
/// Use the [`streaming!`] macro to make a `StreamingHandler` from a closure.
pub fn streaming_append(&mut self, string_writer: Box<dyn StreamingHandler>) {
pub fn streaming_append(&mut self, string_writer: Box<dyn StreamingHandler + Send>) {
self.append_chunk(StringChunk::Stream(string_writer));
}

Expand Down Expand Up @@ -491,7 +491,7 @@ impl<'r, 't, H: HandlerTypes> Element<'r, 't, H> {
///
///
/// Use the [`streaming!`] macro to make a `StreamingHandler` from a closure.
pub fn streaming_set_inner_content(&mut self, string_writer: Box<dyn StreamingHandler>) {
pub fn streaming_set_inner_content(&mut self, string_writer: Box<dyn StreamingHandler + Send>) {
self.set_inner_content_chunk(StringChunk::Stream(string_writer));
}

Expand Down Expand Up @@ -542,7 +542,7 @@ impl<'r, 't, H: HandlerTypes> Element<'r, 't, H> {
///
///
/// Use the [`streaming!`] macro to make a `StreamingHandler` from a closure.
pub fn streaming_replace(&mut self, string_writer: Box<dyn StreamingHandler>) {
pub fn streaming_replace(&mut self, string_writer: Box<dyn StreamingHandler + Send>) {
self.replace_chunk(StringChunk::Stream(string_writer));
}

Expand Down
6 changes: 3 additions & 3 deletions src/rewritable_units/mutations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl Mutations {

pub(crate) enum StringChunk {
Buffer(Box<str>, ContentType),
Stream(Box<dyn StreamingHandler>),
Stream(Box<dyn StreamingHandler + Send>),
}

impl StringChunk {
Expand Down Expand Up @@ -137,7 +137,7 @@ impl DynamicString {
}

/// A callback used to write content asynchronously.
pub trait StreamingHandler: Send {
pub trait StreamingHandler {
/// This method is called only once, and is expected to write content
/// by calling the [`sink.write_str()`](StreamingHandlerSink::write_str) one or more times.
///
Expand All @@ -152,7 +152,7 @@ pub trait StreamingHandler: Send {
impl RefUnwindSafe for StringChunk {}
impl UnwindSafe for StringChunk {}

impl<F> From<F> for Box<dyn StreamingHandler>
impl<F> From<F> for Box<dyn StreamingHandler + Send>
where
F: FnOnce(&mut StreamingHandlerSink<'_>) -> BoxResult + Send + 'static,
{
Expand Down
6 changes: 3 additions & 3 deletions src/rewritable_units/tokens/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl<'i> Comment<'i> {
///
/// Use the [`streaming!`] macro to make a `StreamingHandler` from a closure.
#[inline]
pub fn streaming_before(&mut self, string_writer: Box<dyn StreamingHandler>) {
pub fn streaming_before(&mut self, string_writer: Box<dyn StreamingHandler + Send>) {
self.mutations
.mutate()
.content_before
Expand Down Expand Up @@ -168,7 +168,7 @@ impl<'i> Comment<'i> {
///
/// Use the [`streaming!`] macro to make a `StreamingHandler` from a closure.
#[inline]
pub fn streaming_after(&mut self, string_writer: Box<dyn StreamingHandler>) {
pub fn streaming_after(&mut self, string_writer: Box<dyn StreamingHandler + Send>) {
self.mutations
.mutate()
.content_after
Expand Down Expand Up @@ -215,7 +215,7 @@ impl<'i> Comment<'i> {
///
/// Use the [`streaming!`] macro to make a `StreamingHandler` from a closure.
#[inline]
pub fn streaming_replace(&mut self, string_writer: Box<dyn StreamingHandler>) {
pub fn streaming_replace(&mut self, string_writer: Box<dyn StreamingHandler + Send>) {
self.mutations
.mutate()
.replace(StringChunk::Stream(string_writer));
Expand Down
6 changes: 3 additions & 3 deletions src/rewritable_units/tokens/end_tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl<'i> EndTag<'i> {
///
/// Use the [`streaming!`] macro to make a `StreamingHandler` from a closure.
#[inline]
pub fn streaming_before(&mut self, string_writer: Box<dyn StreamingHandler>) {
pub fn streaming_before(&mut self, string_writer: Box<dyn StreamingHandler + Send>) {
self.mutations
.mutate()
.content_before
Expand All @@ -116,7 +116,7 @@ impl<'i> EndTag<'i> {
///
/// Use the [`streaming!`] macro to make a `StreamingHandler` from a closure.
#[inline]
pub fn streaming_after(&mut self, string_writer: Box<dyn StreamingHandler>) {
pub fn streaming_after(&mut self, string_writer: Box<dyn StreamingHandler + Send>) {
self.mutations
.mutate()
.content_after
Expand All @@ -129,7 +129,7 @@ impl<'i> EndTag<'i> {
///
/// Use the [`streaming!`] macro to make a `StreamingHandler` from a closure.
#[inline]
pub fn streaming_replace(&mut self, string_writer: Box<dyn StreamingHandler>) {
pub fn streaming_replace(&mut self, string_writer: Box<dyn StreamingHandler + Send>) {
self.mutations
.mutate()
.replace(StringChunk::Stream(string_writer));
Expand Down
6 changes: 3 additions & 3 deletions src/rewritable_units/tokens/start_tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl<'i> StartTag<'i> {
/// Consequent calls to the method append to the previously inserted content.
///
/// Use the [`streaming!`] macro to make a `StreamingHandler` from a closure.
pub fn streaming_before(&mut self, string_writer: Box<dyn StreamingHandler>) {
pub fn streaming_before(&mut self, string_writer: Box<dyn StreamingHandler + Send>) {
self.mutations
.mutate()
.content_before
Expand All @@ -157,7 +157,7 @@ impl<'i> StartTag<'i> {
/// Consequent calls to the method prepend to the previously inserted content.
///
/// Use the [`streaming!`] macro to make a `StreamingHandler` from a closure.
pub fn streaming_after(&mut self, string_writer: Box<dyn StreamingHandler>) {
pub fn streaming_after(&mut self, string_writer: Box<dyn StreamingHandler + Send>) {
self.mutations
.mutate()
.content_after
Expand All @@ -169,7 +169,7 @@ impl<'i> StartTag<'i> {
/// Consequent calls to the method overwrite previous replacement content.
///
/// Use the [`streaming!`] macro to make a `StreamingHandler` from a closure.
pub fn streaming_replace(&mut self, string_writer: Box<dyn StreamingHandler>) {
pub fn streaming_replace(&mut self, string_writer: Box<dyn StreamingHandler + Send>) {
self.mutations
.mutate()
.replace(StringChunk::Stream(string_writer));
Expand Down
6 changes: 3 additions & 3 deletions src/rewritable_units/tokens/text_chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ impl<'i> TextChunk<'i> {
/// Consequent calls to the method append `content` to the previously inserted content.
///
/// Use the [`streaming!`] macro to make a `StreamingHandler` from a closure.
pub fn streaming_before(&mut self, string_writer: Box<dyn StreamingHandler>) {
pub fn streaming_before(&mut self, string_writer: Box<dyn StreamingHandler + Send>) {
self.mutations
.mutate()
.content_before
Expand All @@ -283,7 +283,7 @@ impl<'i> TextChunk<'i> {
/// Consequent calls to the method prepend to the previously inserted content.
///
/// Use the [`streaming!`] macro to make a `StreamingHandler` from a closure.
pub fn streaming_after(&mut self, string_writer: Box<dyn StreamingHandler>) {
pub fn streaming_after(&mut self, string_writer: Box<dyn StreamingHandler + Send>) {
self.mutations
.mutate()
.content_after
Expand All @@ -295,7 +295,7 @@ impl<'i> TextChunk<'i> {
/// Consequent calls to the method overwrite previous replacement content.
///
/// Use the [`streaming!`] macro to make a `StreamingHandler` from a closure.
pub fn streaming_replace(&mut self, string_writer: Box<dyn StreamingHandler>) {
pub fn streaming_replace(&mut self, string_writer: Box<dyn StreamingHandler + Send>) {
self.mutations
.mutate()
.replace(StringChunk::Stream(string_writer));
Expand Down
4 changes: 2 additions & 2 deletions src/rewriter/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,13 +538,13 @@ macro_rules! streaming {
) -> StreamingHandler
where
StreamingHandler:
FnOnce(&mut StreamingHandlerSink<'_>) -> Result<(), Box<dyn Error + Send + Sync>> + 'static + Send,
FnOnce(&mut StreamingHandlerSink<'_>) -> Result<(), Box<dyn Error + Send + Sync>> + 'static,
{
handler_closure
}

Box::new(streaming_macro_type_hint($closure))
as Box<dyn $crate::html_content::StreamingHandler>
as Box<dyn $crate::html_content::StreamingHandler + Send>
}};
}

Expand Down

0 comments on commit 9a124eb

Please sign in to comment.