Skip to content

Input/Output with ard/io

The ard/io module provides basic input and output operations for console interaction.

The io module provides:

  • Console output with the print function
  • Console input with the read_line function
  • Automatic string conversion via the ToString trait
use ard/io
fn main() {
io::print("What's your name?")
let name = io::read_line().expect("Failed to read")
io::print("Hello, {name}!")
}

Print a value to the console. The value must implement the Str::ToString trait, which all built-in primitive types implement.

use ard/io
io::print("Hello, world!")
io::print(42)
io::print(true)

Read a line from standard input. Returns a result containing the input string or an error if reading fails.

use ard/io
let input = io::read_line().expect("Failed to read line")
use ard/io
fn main() {
io::print("Hello, world!")
io::print("Enter your name: ")
let name = io::read_line().expect("Failed to read name")
io::print("Hello, {name}!")
}
use ard/io
fn main() {
io::print("Number: 42")
io::print("Boolean: true")
io::print("Float: 3.14")
}
use ard/io
use ard/int
fn main() {
io::print("Enter a number: ")
let input = io::read_line().expect("Failed to read")
match Int::from_str(input) {
num => io::print("You entered: {num.to_str()}"),
_ => io::print("Invalid input")
}
}
use ard/io
struct Person {
name: Str,
age: Int
}
fn main() {
let person = Person { name: "Alice", age: 30 }
io::print("Name: {person.name}")
io::print("Age: {person.age}")
}