Run Rust Modules
Lesson 1 of 48 in Coddy's Rust for Java Developers course.
You already organize Java programs around classes and methods. This course builds Rust console programs from modules, owned values and explicit interfaces. Start by running the supplied program unchanged. It has one locked main.rs entry point and an editable sibling module. Later tasks build on ownership and borrowing without Cargo, external crates or unsafe code.
The runner invokes rustc main.rs -C debuginfo=0 without an edition flag, so these examples and tasks use Rust 2015 edition. Java comparison programs use Java 17. The modern compiler accepts the trait-object syntax shown later even in this edition.
Challenge
EasyRun 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 Java Developers
1First Rust Programs
Run Rust ModulesOutput and CommentsModules and VisibilityBindings and TypesNumbers and CastsRecap: Storage Invoice4Ownership and Borrowing
Ownership and MovesShared BorrowsMutable BorrowsLifetimes and ViewsBorrowing Recap3Functions and Sequences
Functions and ReturnsArrays and SlicesVectors and IterationRecap: Record ReadingsPractice on your own: Online Rust compiler