Tour of Rust Inhoudsopgave

Inline Module

Een submodule kan direct inline worden geplaatst binnen de code van een module.

Een heel gebruikelijk gebruik van inline modules is het maken van unit tests. We maken een inline module die alleen bestaat wanneer Rust wordt gebruikt voor testen!

// This macro removes this inline module when Rust
// is not in test mode.
#[cfg(test)]
mod tests {
    // Notice that we don't immediately get access to the
    // parent module. We must be explicit.
    use super::*;

    ... tests go here ...
}
Mascot Ferris