Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@lupyuen
Created January 22, 2020 10:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lupyuen/5360769a2d92ec50d988cce92622abff to your computer and use it in GitHub Desktop.
Save lupyuen/5360769a2d92ec50d988cce92622abff to your computer and use it in GitHub Desktop.

What's a main function?

In C programs, there's always a function named main that's called to start the application.

Mynewt OS is written in C, so Mynewt uses the same convention... It expects us to provide a C function named main that is called upon startup.

Our application is in Rust not C. We exposed our Rust function named main as a C function, like this...

extern "C" fn main()

Why is the main function in lib.rs not main.rs?

Our Rust Application is actually compiled into a Rust Library that's linked into Mynewt OS.

By convention, a Rust Library must have a lib.rs file that defines the Rust functions (and optionally, includes other Rust source files).

That's why our Rust main function is in lib.rs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment