1st
This commit is contained in:
39
src/lib.rs
39
src/lib.rs
@@ -1,7 +1,36 @@
|
|||||||
#[cfg(test)]
|
#![crate_name = "by_example_024_meta_doc"]
|
||||||
mod tests {
|
|
||||||
#[test]
|
/// A human being is represented here
|
||||||
fn it_works() {
|
pub struct Person {
|
||||||
assert_eq!(2 + 2, 4);
|
/// 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user