lex_hello worked for a second just now

this is just a backup however
This commit is contained in:
2025-02-02 10:20:03 +01:00
parent 2b79e96dc9
commit 1556d54226
45 changed files with 646 additions and 371 deletions

View File

@@ -12,7 +12,9 @@ pub fn derive(input: TokenStream) -> TokenStream {
let decode = decode_body(&input.data);
let expanded = quote! {
impl #impl_generics orchid_api_traits::Decode for #name #ty_generics #where_clause {
async fn decode<R: async_std::io::Read + ?Sized>(mut read: std::pin::Pin<&mut R>) -> Self {
async fn decode<R: orchid_api_traits::async_std::io::Read + ?Sized>(
mut read: std::pin::Pin<&mut R>
) -> Self {
#decode
}
}
@@ -27,7 +29,8 @@ fn decode_fields(fields: &syn::Fields) -> pm2::TokenStream {
let exprs = fields.iter().map(|f| {
let syn::Field { ty, ident, .. } = &f;
quote! {
#ident : < #ty as orchid_api_traits::Decode>::decode(read.as_mut()).await
#ident : (Box::pin(< #ty as orchid_api_traits::Decode>::decode(read.as_mut()))
as std::pin::Pin<Box<dyn std::future::Future<Output = _>>>).await
}
});
quote! { { #( #exprs, )* } }
@@ -36,7 +39,8 @@ fn decode_fields(fields: &syn::Fields) -> pm2::TokenStream {
let exprs = fields.iter().map(|field| {
let ty = &field.ty;
quote! {
< #ty as orchid_api_traits::Decode>::decode(read.as_mut()).await,
(Box::pin(< #ty as orchid_api_traits::Decode>::decode(read.as_mut()))
as std::pin::Pin<Box<dyn std::future::Future<Output = _>>>).await,
}
});
quote! { ( #( #exprs )* ) }

View File

@@ -14,7 +14,12 @@ pub fn derive(input: TokenStream) -> TokenStream {
let encode = encode_body(&input.data);
let expanded = quote! {
impl #e_impl_generics orchid_api_traits::Encode for #name #e_ty_generics #e_where_clause {
async fn encode<W: async_std::io::Write + ?Sized>(&self, mut write: std::pin::Pin<&mut W>) { #encode }
async fn encode<W: orchid_api_traits::async_std::io::Write + ?Sized>(
&self,
mut write: std::pin::Pin<&mut W>
) {
#encode
}
}
};
TokenStream::from(expanded)
@@ -37,7 +42,8 @@ fn encode_body(data: &syn::Data) -> Option<pm2::TokenStream> {
let body = encode_items(&v.fields);
quote! {
Self::#ident #dest => {
(#i as u8).encode(write.as_mut()).await;
(Box::pin((#i as u8).encode(write.as_mut()))
as std::pin::Pin<Box<dyn std::future::Future<Output = _>>>).await;
#body
}
}
@@ -53,7 +59,10 @@ fn encode_body(data: &syn::Data) -> Option<pm2::TokenStream> {
}
fn encode_names<T: ToTokens>(names: impl Iterator<Item = T>) -> pm2::TokenStream {
quote! { #( #names .encode(write.as_mut()).await; )* }
quote! { #(
(Box::pin(#names .encode(write.as_mut()))
as std::pin::Pin<Box<dyn std::future::Future<Output = _>>>).await;
)* }
}
fn encode_items(fields: &syn::Fields) -> Option<pm2::TokenStream> {