Skip to content

Commit 1ef7966

Browse files
ZapAntonpetertseng
authored andcommitted
luhn-from: Added template to the stub file (#613)
Contributes to #551
1 parent 370007d commit 1ef7966

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Stub doesn't compile because the From trait is not implemented for the every type in the test suite.
2+
This exercise is an introduction to the From trait and fully implementing this trait for the test suite reduces learning.

exercises/luhn-from/src/lib.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,18 @@
1+
pub struct Luhn;
12

3+
impl Luhn {
4+
pub fn is_valid(&self) -> bool {
5+
unimplemented!("Determine if the current Luhn struct contains a valid credit card number.");
6+
}
7+
}
8+
9+
/// Here is the example of how the From trait could be implemented
10+
/// for the &str type. Naturally, you can implement this trait
11+
/// by hand for the every other type presented in the test suite,
12+
/// but your solution will fail if a new type is presented.
13+
/// Perhaps there exists a better solution for this problem?
14+
impl<'a> From<&'a str> for Luhn {
15+
fn from(input: &'a str) -> Self {
16+
unimplemented!("From the given input '{}' create a new Luhn struct.", input);
17+
}
18+
}

0 commit comments

Comments
 (0)