Compare commits

..

No commits in common. "04520ffa1e9dbadcda45edb6b9c30264d308b9cd" and "f899a55a08764877434ddc57ea898fe3308ccdfc" have entirely different histories.

View File

@ -1,5 +1,114 @@
fn foo() {
println!("Hello from foo()");
}
fn answer_to_all_questions() -> u32 {
42
}
fn add_two_numbers(a: u32, b: u32) -> u32 {
a + b
}
trait Vector {
fn dot(&self, other: &Self) -> f32;
fn length(&self) -> f32;
}
struct Vector2 {
x: f32,
y: f32,
}
impl Vector2 {
pub fn new(x: f32, y: f32) -> Vector2 {
Vector2 { x, y }
}
}
impl Vector for Vector2 {
fn dot(&self, other: &Vector2) -> f32 {
self.x * other.x + self.y * other.y
}
fn length(&self) -> f32 {
self.dot(self).sqrt()
}
}
struct Vector3 {
x: f32,
y: f32,
z: f32,
}
impl Vector3 {
pub fn new(x: f32, y: f32, z: f32) -> Vector3 {
Vector3 { x, y, z }
}
}
impl Vector for Vector3 {
fn dot(&self, other: &Vector3) -> f32 {
self.x * other.x + self.y * other.y + self.z * other.z
}
fn length(&self) -> f32 {
self.dot(self).sqrt()
}
}
impl std::ops::Add for Vector3 {
type Output = Vector3;
fn add(self, other: Self) -> Self {
Vector3::new(self.x + other.x, self.y + other.y, self.z + other.z)
}
}
struct Meter {
value: f32,
}
impl Meter {
pub fn new(value: f32) -> Meter {
Meter { value }
}
}
struct SquareMeter {
value: f32,
}
impl SquareMeter {
pub fn new(value: f32) -> SquareMeter {
SquareMeter { value }
}
}
impl std::ops::Mul for Meter {
type Output = SquareMeter;
fn mul(self, rhs: Self) -> Self::Output {
SquareMeter::new(self.value * rhs.value)
}
}
fn main() { fn main() {
for value in (-10..10).rev() { let vec1 = Vector3::new(2.0, 0.0, 0.0);
println!("Value: {}", value); let vec2 = Vector3::new(1.0, 1.0, 0.0);
}
let vec3 = vec1 + vec2;
let m1 = Meter::new(10.0);
let m2 = Meter::new(90.0);
let area = m1 * m2;
println!("Hello, world!");
println!("Answer to all questions: {}", answer_to_all_questions());
println!("Add two number: {}", add_two_numbers(23, 42));
println!("x: {}, y: {}, z: {}", vec3.x, vec3.y, vec3.z);
foo();
} }