initial commit
This commit is contained in:
4
exercises/04_traits/07_deref/Cargo.toml
Normal file
4
exercises/04_traits/07_deref/Cargo.toml
Normal file
@@ -0,0 +1,4 @@
|
||||
[package]
|
||||
name = "deref"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
38
exercises/04_traits/07_deref/src/lib.rs
Normal file
38
exercises/04_traits/07_deref/src/lib.rs
Normal file
@@ -0,0 +1,38 @@
|
||||
// TODO: whenever `title` and `description` are returned via their accessor methods, they
|
||||
// should be normalized—i.e. leading and trailing whitespace should be removed.
|
||||
// There is a method in Rust's standard library that can help with this, but you won't
|
||||
// find it in the documentation for `String`.
|
||||
// Can you figure out where it is defined and how to use it?
|
||||
|
||||
pub struct Ticket {
|
||||
title: String,
|
||||
description: String,
|
||||
status: String,
|
||||
}
|
||||
|
||||
impl Ticket {
|
||||
pub fn title(&self) -> &str {
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub fn description(&self) -> &str {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_normalization() {
|
||||
let ticket = Ticket {
|
||||
title: " A title ".to_string(),
|
||||
description: " A description ".to_string(),
|
||||
status: "To-Do".to_string(),
|
||||
};
|
||||
|
||||
assert_eq!("A title", ticket.title());
|
||||
assert_eq!("A description", ticket.description());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user