From ca842d133305148aebd5f27073a253a3888f543f Mon Sep 17 00:00:00 2001 From: Bassem Girgis Date: Sat, 17 Jul 2021 13:37:03 -0500 Subject: [PATCH] 1st --- src/lib.rs | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 31e1bb2..dbff2f2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,36 @@ -#[cfg(test)] -mod tests { - #[test] - fn it_works() { - assert_eq!(2 + 2, 4); +#![crate_name = "by_example_024_meta_doc"] + +/// A human being is represented here +pub struct Person { + /// A person must have a name, no matter how much Juliet may hate it + name: String, +} + +impl Person { + /// Returns a person with the name given them + /// + /// # Arguments + /// + /// * `name` - A string slice that holds the name of the person + /// + /// # Examples + /// + /// ``` + /// // You can have rust code between fences inside the comments + /// // If you pass --test to `rustdoc`, it will even test it for you! + /// use doc::Person; + /// let person = Person::new("name"); + /// ``` + pub fn new(name: &str) -> Person { + Person { + name: name.to_string(), + } + } + + /// Gives a friendly hello! + /// + /// Says "Hello, [name]" to the `Person` it is called on. + pub fn hello(&self) { + println!("Hello, {}!", self.name); } }