There are a few I’m aware of:

  1. Rust-style use (multiple imports per statement, renaming items using as)
  2. Java-style import (single import per statement, no renaming (afaik))
  3. Zig-style let xlib = @import("xlib") (imports as assignments)
  4. C-style #include (no importing, just pastes the code of the named file)
  • Kwdg@discuss.tchncs.de
    link
    fedilink
    arrow-up
    4
    ·
    3 days ago

    It’s actually pretty similar to rust, only that rust can import multiple modules (namespaces) in one line, which is just syntax sugar, and the syntax is slightly different.

    Your example would be

    use my_projext::domain::entities;
    use my_project::api::contracts::routes::http as routes;
    
    • nebeker@programming.dev
      link
      fedilink
      English
      arrow-up
      2
      ·
      3 days ago

      Rust adds the curly brace syntax so you can import a specific subset from a module, but I can’t decide if I like that. In C# you just keep adding extra lines which take up more vertical space, but if you sort your using a alphabetically (which your IDE can do), I think you get a very readable list. In sum, Rust adds a feature that I don’t really actually like.