-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: hyper 1.0 upgrade + custom listeners
- Loading branch information
1 parent
e9b568d
commit 2dfcc1e
Showing
87 changed files
with
3,428 additions
and
2,854 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
use proc_macro2::{TokenStream, Span}; | ||
use devise::{Spanned, Result, ext::SpanDiagnosticExt}; | ||
use syn::{Token, parse_quote, parse_quote_spanned}; | ||
use syn::{TraitItemFn, TypeParamBound, ReturnType, Attribute}; | ||
use syn::punctuated::Punctuated; | ||
use syn::parse::Parser; | ||
|
||
fn _async_bound( | ||
args: proc_macro::TokenStream, | ||
input: proc_macro::TokenStream | ||
) -> Result<TokenStream> { | ||
let bounds = <Punctuated<TypeParamBound, Token![+]>>::parse_terminated.parse(args)?; | ||
if bounds.is_empty() { | ||
return Ok(input.into()); | ||
} | ||
|
||
let mut func: TraitItemFn = syn::parse(input)?; | ||
let original: TraitItemFn = func.clone(); | ||
if !func.sig.asyncness.is_some() { | ||
let diag = Span::call_site() | ||
.error("attribute can only be applied to async fns") | ||
.span_help(func.sig.span(), "this fn declaration must be `async`"); | ||
|
||
return Err(diag); | ||
} | ||
|
||
let doc: Attribute = parse_quote! { | ||
#[doc = concat!( | ||
"# Future Bounds", | ||
"\n", | ||
"**The `Future` generated by this `async fn` must be `", stringify!(#bounds), "`**." | ||
)] | ||
}; | ||
|
||
func.sig.asyncness = None; | ||
func.sig.output = match func.sig.output { | ||
ReturnType::Type(arrow, ty) => parse_quote_spanned!(ty.span() => | ||
#arrow impl ::core::future::Future<Output = #ty> + #bounds | ||
), | ||
default@ReturnType::Default => default | ||
}; | ||
|
||
Ok(quote! { | ||
#[cfg(all(not(doc), rust_analyzer))] | ||
#original | ||
|
||
#[cfg(all(doc, not(rust_analyzer)))] | ||
#doc | ||
#original | ||
|
||
#[cfg(not(any(doc, rust_analyzer)))] | ||
#func | ||
}) | ||
} | ||
|
||
pub fn async_bound( | ||
args: proc_macro::TokenStream, | ||
input: proc_macro::TokenStream | ||
) -> TokenStream { | ||
_async_bound(args, input).unwrap_or_else(|d| d.emit_as_item_tokens()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ pub mod entry; | |
pub mod catch; | ||
pub mod route; | ||
pub mod param; | ||
pub mod async_bound; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.