Skip to content

Commit ea042f8

Browse files
ZapAntonpetertseng
authored andcommitted
luhn-trait: Add template to the stub file (#614)
Contributes to #551
1 parent c6de272 commit ea042f8

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-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 custom trait is not implemented for the every type in the test suite.
2+
This exercise is an introduction to implementing custom traits for the primitives and fully implementing the trait for the test suite reduces learning.

exercises/luhn-trait/src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,14 @@
1+
pub trait Luhn {
2+
fn valid_luhn(&self) -> bool;
3+
}
14

5+
/// Here is the example of how to implement custom Luhn trait
6+
/// for the &str type. Naturally, you can implement this trait
7+
/// by hand for the every other type presented in the test suite,
8+
/// but your solution will fail if a new type is presented.
9+
/// Perhaps there exists a better solution for this problem?
10+
impl<'a> Luhn for &'a str {
11+
fn valid_luhn(&self) -> bool {
12+
unimplemented!("Determine if '{}' is a valid credit card number.", self);
13+
}
14+
}

0 commit comments

Comments
 (0)