Pure Programmer
Blue Matrix


Cluster Map

Tuples

L1

This page is under construction. Please come back later.

Tuples1.rs
fn main() {
	let mut pair1 = ("Hello", 5);
	let mut pair2:(isize, f64);
	let mut pair3:(String, f64);

	pair2 = [3, 3.1415926f64];
	pair3 = ["Goodbye", 1.5f64];

	println!("{},{}", pair1.0, pair1.1);
	println!("{},{}", pair2.0, pair2.1);
	println!("{}", Utils.tupleToString(pair3));
}

Output
$ rustc Tuples1.rs error[E0425]: cannot find value `Utils` in this scope --> Tuples1.rs:11:17 | 11 | println!("{}", Utils.tupleToString(pair3)); | ^^^^^ not found in this scope error[E0308]: mismatched types --> Tuples1.rs:6:14 | 6 | pair2 = [3, 3.1415926f64]; | ^^^^^^^^^^^^ expected integer, found `f64` error[E0308]: mismatched types --> Tuples1.rs:7:22 | 7 | pair3 = ["Goodbye", 1.5f64]; | ^^^^^^ expected `&str`, found `f64` error: aborting due to 3 previous errors Some errors have detailed explanations: E0308, E0425. For more information about an error, try `rustc --explain E0308`.
Tuples2.rs
fn main() {
	let mut pair1 = ("Hello", 5);
	let mut tuple1 = ("Goodbye", 3, 3.1415926f64);
	let mut tuple2 = (1.6f64, 2.5f64, 5, "C");

	println!("{},{}", pair1.0, pair1.1);
	println!("{},{},{}", tuple1.0, tuple1.1, tuple1.2);
	println!("{},{},{},{}", tuple2.0, tuple2.1, tuple2.2, tuple2.3);
}

Output
$ rustc Tuples2.rs warning: variable does not need to be mutable --> Tuples2.rs:2:6 | 2 | let mut pair1 = ("Hello", 5); | ----^^^^^ | | | help: remove this `mut` | = note: `#[warn(unused_mut)]` on by default warning: variable does not need to be mutable --> Tuples2.rs:3:6 | 3 | let mut tuple1 = ("Goodbye", 3, 3.1415926f64); | ----^^^^^^ | | | help: remove this `mut` warning: variable does not need to be mutable --> Tuples2.rs:4:6 | 4 | let mut tuple2 = (1.6f64, 2.5f64, 5, "C"); | ----^^^^^^ | | | help: remove this `mut` warning: 3 warnings emitted $ ./Tuples2 Hello,5 Goodbye,3,3.1415926 1.6,2.5,5,C

Questions

Projects

More ★'s indicate higher difficulty level.

References