Arrr, me hearty! Ye be askin’ for a simple piece o’ code in Rust, peppered with pirate comments. Here be a wee program that prints a hearty greeting:

fn main() {
    // Avast, me hearties! We start our voyage here.
    let greeting = "Ahoy, matey! Welcome aboard!";

    // Yo ho ho! We print our greeting to the open sea!
  println!("{}", greeting);
}

Now ye be havin’ a taste o’ pirate-infused Rust code! If ye be havin’ any more requests or need further assistance, feel free to speak up, and I’ll be at yer service!

  • aussiematt@lemm.ee
    link
    fedilink
    English
    arrow-up
    18
    arrow-down
    2
    ·
    1 year ago

    When I compiled that program, the executable was around 10MB. I wrote the same program in C, and the executable was 15kB. That’s about 3 orders of magnitude difference. Is Rust really 1000 times better than C? :-)

      • aussiematt@lemm.ee
        link
        fedilink
        arrow-up
        5
        ·
        1 year ago

        Thanks for the resources. I’m old school, and so far haven’t really looked into Rust; I look forward to watching the talk you linked to.

      • voxel@sopuli.xyz
        link
        fedilink
        arrow-up
        1
        ·
        1 year ago

        this is not due to safety but rather std. Set opt level to 3 and enable fat lto

    • cmnybo@discuss.tchncs.de
      link
      fedilink
      English
      arrow-up
      15
      ·
      1 year ago

      I wrote it in C and compiled it for an ATtiny13 and it was 162 bytes. That includes the code to initialize the microcontroller and a bit banged transmit only UART to actually output the text.

    • Kirottu@kbin.social
      link
      fedilink
      arrow-up
      15
      ·
      1 year ago

      The standard lib is statically linked, so there will be a higher baseline binary size. This means that yes, a hello world project may be 10mb unstripped but a considerably more complicated project could in turn be 11mb unstripped. Aka it doesn’t matter much in practice.

    • voxel@sopuli.xyz
      link
      fedilink
      English
      arrow-up
      1
      ·
      1 year ago

      set opt level to 3 and enable fat lto.
      even without fat lto enabled, my entire multithreaded voxel engine with multithreaded procedural world generation, procedural structures and multiplayer is 5mb in size.