#is it a good idea to wrap fn main in a macro that my library provides?
27 messages · Page 1 of 1 (latest)
have you seen #[tokio::main] before?
Yes, but it has been a long story https://discord.com/channels/273534239310479360/1219708993669304631
actually, even actix has a #[actix_web::main]
anyway, the point is, "wrapping" main is ok, but I'd prefer an attribute macro so that main still exists
yes, if I could figure it out 😢.
and you should keep in mind that it will conflict with all other libraries that are "wrapping" main
so just make sure that your library can be used without wrapping main
yup, my aim in other post was to know how I can import async_std in my library in a way that the user using my library won't have to imoprt async-std but "only" import my library and get those features from that.
now, because that didn't work, I am finding out alternative ways
yes, thanks for your help
yeah i just looked at the other post
i think this is fine, but the problem is someone looking for the program entry point will be looking for a fn main
so I'd make sure that this will still be present
oops, sorry for imposing such a huge problem like this (tagging the deleted message)
I changed the macro right now, is this fine and recommended?:
fn main() {
rohanasan! {
println!("Listening at http://localhost:8080");
serve(init(8080), handle).await;
}
}
this also works:
fn main() {
println!("Listening at http://localhost:8080");
rohanasan! {
serve(init(8080), handle).await;
}
}
I believe this wont confuse people
sure, that's fine. though at this point, do you even need a macro? you could do
fn main() {
rohanasan(async {
serve(init(8080), handle).await
});
}
which is basically what you do with async_std when not using a macro
https://docs.rs/tokio-async-std/latest/async_std/task/fn.block_on.html
API documentation for the Rust block_on fn in crate async_std.
Yes, my main aim is to make my library easy to use, so:
fn main() {
rohanasan(async {
serve(init(8080), handle).await
});
}
This looks much easier and welcoming:
fn main() {
rohanasan!(
serve(init(8080), handle).await;);
}
i personally don't think it makes a huge difference, but if you're happy with it, it's fine
Thanks 😄
Only if there was a way to do:
#[rohanasan]
async fn main(){
}
Without letting person using my library import async_std
you can, you just have to write your own attribute macro
Yes