From 50a2c87f827e34d27b941108dd5aafe3e58c1ea5 Mon Sep 17 00:00:00 2001 From: clubby789 Date: Tue, 30 Jan 2024 18:13:16 +0000 Subject: [PATCH] Document importing `main` --- src/crates-and-source-files.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/crates-and-source-files.md b/src/crates-and-source-files.md index 8d54c3f6b..3f660e7e1 100644 --- a/src/crates-and-source-files.md +++ b/src/crates-and-source-files.md @@ -119,6 +119,17 @@ fn main() -> impl std::process::Termination { } ``` +The `main` function may be an import, e.g. from an external crate or from the current one. + +```rust +mod foo { + pub fn bar() { + println!("Hello, world!"); + } +} +use foo::bar as main; +``` + > **Note**: Types with implementations of [`Termination`] in the standard library include: > > * `()`