Filling in 1.2.3
This commit is contained in:
parent
78f5972b30
commit
cb36ed01b2
4
rustbyexample/0123/Cargo.lock
generated
Normal file
4
rustbyexample/0123/Cargo.lock
generated
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
[root]
|
||||||
|
name = "0123"
|
||||||
|
version = "0.1.0"
|
||||||
|
|
6
rustbyexample/0123/Cargo.toml
Normal file
6
rustbyexample/0123/Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "0123"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Dan Buch <daniel.buch@gmail.com>"]
|
||||||
|
|
||||||
|
[dependencies]
|
42
rustbyexample/0123/src/main.rs
Normal file
42
rustbyexample/0123/src/main.rs
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
use std::fmt::{self, Formatter, Display};
|
||||||
|
|
||||||
|
struct City {
|
||||||
|
name: &'static str,
|
||||||
|
lat: f32,
|
||||||
|
lon: f32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for City {
|
||||||
|
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
||||||
|
let lat_c = if self.lat >= 0.0 { 'N' } else { 'S' };
|
||||||
|
let lon_c = if self.lon >= 0.0 { 'E' } else { 'S' };
|
||||||
|
|
||||||
|
write!(f, "{}: {:.3}˚{} {:.3}˚{}",
|
||||||
|
self.name, self.lat.abs(), lat_c, self.lon.abs(), lon_c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct Color {
|
||||||
|
red: u8,
|
||||||
|
green: u8,
|
||||||
|
blue: u8,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
for city in [
|
||||||
|
City { name: "Dublin", lat: 53.347778, lon: -6.259722 },
|
||||||
|
City { name: "Oslo", lat: 59.95, lon: 10.75 },
|
||||||
|
City { name: "Vancouver", lat: 49.25, lon: -123.1 },
|
||||||
|
].iter() {
|
||||||
|
println!("{}", *city);
|
||||||
|
}
|
||||||
|
|
||||||
|
for color in [
|
||||||
|
Color { red: 128, green: 255, blue: 90 },
|
||||||
|
Color { red: 0, green: 3, blue: 254 },
|
||||||
|
Color { red: 0, green: 0, blue: 0 },
|
||||||
|
].iter() {
|
||||||
|
println!("{:?}", *color);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user