box-o-sand/rustbyexample/hello/print.rs

33 lines
752 B
Rust
Raw Normal View History

2020-06-08 15:19:33 +00:00
fn main() {
println!("{} days", 31);
println!("{0}, this is {1}. {1}, this is {0}", "Alice", "Bob");
2021-09-10 14:40:48 +00:00
println!(
"{subject} {verb} {object}",
object = "the lazy dog",
subject = "the quick brown fox",
verb = "jumps over"
);
2020-06-08 15:19:33 +00:00
2021-09-10 14:40:48 +00:00
println!(
"{} of {:b} people know binary, the other half doesn't",
1, 2
);
2020-06-08 15:19:33 +00:00
2021-09-10 14:40:48 +00:00
println!("{number:>width$}", number = 1, width = 6);
2020-06-08 15:19:33 +00:00
2021-09-10 14:40:48 +00:00
println!("{number:>0width$}", number = 1, width = 6);
2020-06-08 15:19:33 +00:00
2020-06-08 15:24:43 +00:00
println!("My name is {0}, {1} {0}", "Bond", "James");
2020-06-08 15:19:33 +00:00
#[allow(dead_code)]
2020-06-08 15:24:43 +00:00
#[derive(Debug)]
2020-06-08 15:19:33 +00:00
struct Structure(i32);
2020-06-08 15:24:43 +00:00
println!("This struct `{:?}` will print...", Structure(3));
let pi = 3.141592;
println!("Pi is roughly {:.3}", pi);
2020-06-08 15:19:33 +00:00
}