Skip to content

Commit 5faa26c

Browse files
committed
Update lib.rs
Rearrange functions
1 parent 803afb3 commit 5faa26c

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

src/lib.rs

+25-25
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,31 @@ use rand::Rng;
1919

2020
//Public Functions
2121

22+
/// Generates a valid product key
23+
///
24+
/// # Example
25+
///
26+
/// ```
27+
/// use keyforge95::generate_product_key;
28+
/// for _ in 0..10 {
29+
/// let product_key: String = generate_product_key("retail"); // Both, "retail" and "oem" are available
30+
/// assert_eq!(product_key.len(), 11);
31+
/// assert_eq!(product_key.chars().nth(3).unwrap(), '-');
32+
/// }
33+
/// ```
34+
#[must_use]
35+
pub fn generate_product_key(key_type: &str) -> String {
36+
match key_type {
37+
"retail" => {
38+
// Use generate_block() for product key generation and print it with the right format
39+
format!("{}-{}", generate_block("a"), generate_block("b"))
40+
}
41+
_ => {
42+
panic!("Invalid choice: {key_type}. Only 'retail' or 'oem' allowed.");
43+
}
44+
}
45+
}
46+
2247
/// Tests if a product key is valid
2348
///
2449
/// # Examples
@@ -76,31 +101,6 @@ pub fn validate_product_key(product_key: &str) -> bool {
76101
}
77102
}
78103

79-
/// Generates a valid product key
80-
///
81-
/// # Example
82-
///
83-
/// ```
84-
/// use keyforge95::generate_product_key;
85-
/// for _ in 0..10 {
86-
/// let product_key: String = generate_product_key("retail"); // Both, "retail" and "oem" are available
87-
/// assert_eq!(product_key.len(), 11);
88-
/// assert_eq!(product_key.chars().nth(3).unwrap(), '-');
89-
/// }
90-
/// ```
91-
#[must_use]
92-
pub fn generate_product_key(key_type: &str) -> String {
93-
match key_type {
94-
"retail" => {
95-
// Use generate_block() for product key generation and print it with the right format
96-
format!("{}-{}", generate_block("a"), generate_block("b"))
97-
}
98-
_ => {
99-
panic!("Invalid choice: {key_type}. Only 'retail' or 'oem' allowed.");
100-
}
101-
}
102-
}
103-
104104
// Functions
105105

106106
fn generate_block(choice: &str) -> String {

0 commit comments

Comments
 (0)