init
This commit is contained in:
parent
9ab6ccccb2
commit
bac5b0d34b
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -14,3 +14,8 @@ Cargo.lock
|
|||
# MSVC Windows builds of rustc generate these, which store debugging information
|
||||
*.pdb
|
||||
|
||||
|
||||
|
||||
# Added by cargo
|
||||
|
||||
/target
|
||||
|
|
12
Cargo.toml
Normal file
12
Cargo.toml
Normal file
|
@ -0,0 +1,12 @@
|
|||
[package]
|
||||
name = "webhook-test"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
chrono = "0.4.30"
|
||||
|
||||
[dev-dependencies]
|
||||
chrono = "0.4.30"
|
36
src/main.rs
Normal file
36
src/main.rs
Normal file
|
@ -0,0 +1,36 @@
|
|||
use chrono::Datelike;
|
||||
|
||||
pub struct User<'a> {
|
||||
name: &'a str,
|
||||
dob: u32,
|
||||
}
|
||||
|
||||
impl<'a> User<'a> {
|
||||
pub fn new(name: &'a str, dob: u32) -> User<'a> {
|
||||
User { name, dob }
|
||||
}
|
||||
|
||||
pub fn age(&self) -> u32 {
|
||||
let current_year = chrono::Utc::now().year() as u32;
|
||||
current_year - self.dob
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let user = User::new("Anh Nguyen", 1999);
|
||||
|
||||
println!("User name: {}", user.name);
|
||||
println!("User age: {}", user.age());
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_user_age() {
|
||||
let user = User::new("Test User", 2000);
|
||||
let age = user.age();
|
||||
assert_eq!(age, 23); // Adjust the expected age based on the current year
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user