What does `pub main()` do?

Hi. I'm going through the Tokio tutorial right now, and I'm wondering what does pub main() do? Does making the main function public do anything special compared to just main?

It is not a valid syntax as you can see on playground: Rust Playground

I'm pretty sure they meant pub fn main(), which is valid syntax.


pub fn main() has no effect in an executable binary, but if you also build a library from the same source file, then it will allow code from other crates to call the main function. (This is a rare situation; typical Cargo projects do not use the same root file for both a binary crate and a library crate.)

1 Like