mod front_of_house;
pub use front_of_house::hosting;
pub fn eat_at_restaurant() {
hosting::add_to_waitlist();
}
pub trait Summary {
fn summarize_author(&self) -> String;
fn summarize(&self) -> String {
format!("Read more from {}...", self.summarize_author())
}
}
struct News {
pub headline: String,
pub location: String,
pub author: String,
pub content: String,
}
pub struct Tweet {
pub author: String,
pub content: String,
pub reply_number: usize,
pub can_retweet: bool,
}
impl Summary for News {
fn summarize_author(&self) -> String {
self.author.to_string()
}
fn summarize(&self) -> String {
format!("{}, by {} ({})", self.headline, self.author, self.location)
}
}
impl Summary for Tweet {
fn summarize_author(&self) -> String {
self.author.to_string()
}
}
pub struct Rectangle {
pub width: u32,
pub height: u32
}
impl Rectangle {
pub fn area(self: &Self) -> u32 {
self.height * self.height
}
pub fn square(size: u32) -> Self {
Self { width: size, height: size }
}
fn can_hold(&self, other: &Self) -> bool {
self.width > other.width && self.height > other.height
}
}
mod guess;
#[cfg(test)]
mod tests {
#[test]
fn test_add() {
assert_eq!(2 + 2, 4);
}
use super::*;
#[test]
fn larger_can_hold_smaller() {
let larger = Rectangle {
width: 8,
height: 7,
};
let smaller = Rectangle {
width: 5,
height: 1,
};
assert!(larger.can_hold(&smaller));
}
fn greeting(name: &str) -> String {
format!("heelo,{}", name)
}
#[test]
fn contain_name() {
let result = greeting("dawson");
assert!(
result.contains("dawson"),
"not contain nmae, value was {}",
result
);
}
use guess::Guess;
#[test]
#[should_panic(expected = "Guess value must be between 1 - 100")] fn greter_than_100() {
Guess::new(200);
}
#[test]
#[ignore]
fn it_works() -> Result<(), String> {
if 2 + 2 == 4 {
Ok(())
} else {
Err(String::from("2 + 2 != 4"))
}
}
}
pub fn add_two(num: i32) -> i32 {
num + 2
}