File compilation structure issue

⚓ Rust    📅 2026-01-11    👤 surdeus    👁️ 2      

surdeus

well hi I am new to rust and I am Learning it I request some help here is the context:

in the code bellow I build a simple game its working very fine but...

mod scenario1;
use std::io;

fn main() {
    let mut _character_name = String::from("link");
    const _PLAYER_DAMAGE: i32 = 10;
    let mut _link_has_ms: bool = false;
    loop {
        println!(
            "Oh look! its {_character_name} i wonder what hes doin you head and look his name displaying on the top of his head "
        );
        let mut inputt = String::new();
        println!("do you want to borrow his name or nah");
        match io::stdin().read_line(&mut inputt) {
            Ok(_) => {
                let inputt = inputt.trim();
                if inputt == "borrow" {
                    let an_empty_name = &_character_name;
                    println!(
                        "{} name BEEN borrowed..WAIT Links name?? now its your name!?",
                        an_empty_name
                    );
                    println!("Link took back his name grunting {}", _character_name);
                } else if inputt == "nah" {
                    println!("too bad stay nameless then");
                    break;
                }
                break;
            }
            Err(error) => {
                println!(" {error}");
                break;
            }
        }
    }
}

after success of creating my first rust code I decided to create a new rust file scenario2 but it seems I cant run it and can be only used as a mod I also have no idea about but now assuming it works like the io::std but I cant really use it and worse I cant run it due the cargo project only runs main could someone help me explain how mod keyword works? and why can I only run the main.rs file?

pub fn crss() {
    const _SWORD_DAMAGE: i32 = 40;
    const _DURABILITY_THERESHOLD: i32 = 400;
    const _AIR_SLASH_RANGE: u32 = 200;
    const _AIR_SLASH_DMG: i32 = 15;
}
pub fn link_owns_it() {
    let mut _deku_tree = String::from("master sword");
    const _SWORD_OWNER: &'static str = "link";
    if _SWORD_OWNER == "link" {
        let owns_it = _deku_tree;
        println!("{} link now owns the master sword", owns_it);
    }
}

1 post - 1 participant

Read full topic

🏷️ Rust_feed