Menu
CoddyTech

Run Rust Modules

Lesson 1 of 48 in Coddy's Rust for JavaScript Developers course.

You already write JavaScript, where every value carries its type at runtime, a mistake often surfaces only when that line runs, and a garbage collector frees objects you can no longer reach. Rust checks types, ownership and borrowing before the program runs, then compiles native code with no garbage collector. Start by running the supplied files unchanged. The locked main.rs connects the visible sibling modules and handles input and output, much as a small Node entry script would read stdin and print a result. Later lessons explain those declarations before asking you to write them. This course uses the deployed Rust 2015 edition with a current compiler, the standard library, and no Cargo or external crates, so there is no equivalent of package.json or npm install. JavaScript comparisons describe modern JavaScript as Node runs it, and they focus on what happens at runtime.

challenge icon

Challenge

Easy

Run the supplied files without edits. No input is required. The program prints Rust is ready. welcome::message() -> &'static str supplies the message and exercise::solve returns it.

Implement the required exported APIs and return the result from exercise::solve(input: &str) -> String without a final newline. Do not print in editable code. The locked driver checks required APIs independently, reads all stdin, and prints the returned text with one final newline.

Your code goes in exercise.rs, welcome.rs. main.rs holds the supplied input/output code and cannot be edited.

Try it yourself

#![allow(dead_code, unused_imports, unused_variables, unused_mut)]
mod exercise;
mod welcome;
use std::io::{self, Read};
fn main() {
    let mut input=String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    // BEGIN PUBLIC API PROBES

    // END PUBLIC API PROBES
    println!("{}", exercise::solve(&input));
}

All lessons in Rust for JavaScript Developers

Practice on your own: Online Rust compiler