Skip to content
This repository was archived by the owner on Jun 6, 2025. It is now read-only.

Commit b08ef29

Browse files
committed
Updates
1 parent d0227d9 commit b08ef29

File tree

16 files changed

+144
-128
lines changed

16 files changed

+144
-128
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Or start a customization with the following code:
2626
use rowid::{RowIDWithConfig, RowIDWithConfigResult};
2727

2828
let rwc: RowIDWithConfigResult = RowIDWithConfig::new()
29-
.char_list("0123456789ABCDEFGHJKMNPQRSTVWXYZ".to_string())
29+
.char_list("0123456789ABCDEFGHJKMNPQRSTVWXYZ")
3030
.randomness_length(22)
3131
.done()
3232
.unwrap();

__test__/src/lib.rs

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ mod tests {
88
GenerateResult, RowIDWithConfig, RowIDWithConfigResult, VerifyResult,
99
};
1010

11-
use rowid::errors::{
12-
DECODE_ECD_INVALID_ERR, DECODE_ECD_LENGTH_ERR,
13-
RWC_DONE_CHAR_LIST_LENGTH_ERR,
14-
};
11+
use rowid::RowIDError;
1512

1613
// system_time_to_timestamp
1714

@@ -92,7 +89,7 @@ mod tests {
9289
#[test]
9390
fn test_decode() {
9491
let current: SystemTime = SystemTime::now();
95-
let decoded: SystemTime = decode(encode(current).unwrap()).unwrap();
92+
let decoded: SystemTime = decode(&encode(current).unwrap()).unwrap();
9693
assert!(
9794
system_time_to_timestamp(decoded)
9895
== system_time_to_timestamp(current)
@@ -101,24 +98,24 @@ mod tests {
10198

10299
#[test]
103100
fn test_decode_length_error() {
104-
let result: io::Error = match decode("ABC123".to_string()) {
101+
let result: io::Error = match decode("ABC123") {
105102
| Ok(_) => return assert!(false),
106103
| Err(e) => e,
107104
};
108105

109106
assert!(result.kind() == io::ErrorKind::InvalidInput);
110-
assert!(result.to_string() == DECODE_ECD_LENGTH_ERR);
107+
assert!(result.to_string() == RowIDError::EncodedLength.as_str());
111108
}
112109

113110
#[test]
114111
fn test_decode_invalid_input_error() {
115-
let result: io::Error = match decode("ab^!@#$agastgyaSER".to_string()) {
112+
let result: io::Error = match decode("ab^!@#$agastgyaSER") {
116113
| Ok(_) => return assert!(false),
117114
| Err(e) => e,
118115
};
119116

120117
assert!(result.kind() == io::ErrorKind::InvalidInput);
121-
assert!(result.to_string() == DECODE_ECD_INVALID_ERR);
118+
assert!(result.to_string() == RowIDError::InvalidEncoded.as_str());
122119
}
123120

124121
// generate
@@ -130,7 +127,7 @@ mod tests {
130127
let id: String = generated.result.unwrap();
131128
assert!(generated.success == true);
132129
assert!(
133-
system_time_to_timestamp(decode(id.clone()).unwrap())
130+
system_time_to_timestamp(decode(&id).unwrap())
134131
== system_time_to_timestamp(current)
135132
);
136133
assert!(id.len() == 16);
@@ -142,7 +139,7 @@ mod tests {
142139
fn test_verify() {
143140
let current: SystemTime = SystemTime::now();
144141
let id: String = generate(current, Some(6)).result.unwrap();
145-
let verified: VerifyResult = verify(id);
142+
let verified: VerifyResult = verify(&id);
146143
assert!(verified.success == true);
147144
assert!(match verified.result {
148145
| Some(r) =>
@@ -154,7 +151,7 @@ mod tests {
154151

155152
#[test]
156153
fn test_verify_length_error() {
157-
let verified: VerifyResult = verify("ABC123".to_string());
154+
let verified: VerifyResult = verify("ABC123");
158155

159156
assert!(verified.success == false);
160157

@@ -164,12 +161,12 @@ mod tests {
164161
};
165162

166163
assert!(error.kind() == io::ErrorKind::InvalidInput);
167-
assert!(error.to_string() == DECODE_ECD_LENGTH_ERR);
164+
assert!(error.to_string() == RowIDError::EncodedLength.as_str());
168165
}
169166

170167
#[test]
171168
fn test_verify_invalid_input_error() {
172-
let verified: VerifyResult = verify("ab^!@#$agastgyaSER".to_string());
169+
let verified: VerifyResult = verify("ab^!@#$agastgyaSER");
173170

174171
assert!(verified.success == false);
175172

@@ -179,21 +176,21 @@ mod tests {
179176
};
180177

181178
assert!(error.kind() == io::ErrorKind::InvalidInput);
182-
assert!(error.to_string() == DECODE_ECD_INVALID_ERR);
179+
assert!(error.to_string() == RowIDError::InvalidEncoded.as_str());
183180
}
184181

185182
// rowid_with_config
186183

187184
#[test]
188185
fn test_rowid_with_config_char_list_length_error() {
189186
let err: io::Error =
190-
match RowIDWithConfig::new().char_list("ABC".to_string()).done() {
187+
match RowIDWithConfig::new().char_list("ABC").done() {
191188
| Ok(_) => return assert!(false),
192189
| Err(e) => e,
193190
};
194191

195192
assert!(err.kind() == io::ErrorKind::InvalidInput);
196-
assert!(err.to_string() == RWC_DONE_CHAR_LIST_LENGTH_ERR);
193+
assert!(err.to_string() == RowIDError::CharListLength.as_str());
197194
}
198195

199196
#[test]
@@ -223,7 +220,7 @@ mod tests {
223220

224221
let current: SystemTime = SystemTime::now();
225222
let decoded: SystemTime =
226-
rwc.decode(rwc.encode(current).unwrap()).unwrap();
223+
rwc.decode(&rwc.encode(current).unwrap()).unwrap();
227224

228225
assert!(
229226
system_time_to_timestamp(decoded)
@@ -241,9 +238,9 @@ mod tests {
241238
let id: String = generated.result.unwrap();
242239

243240
assert!(generated.success == true);
244-
assert!(id.clone().len() == 16);
241+
assert!(id.len() == 16);
245242
assert!(
246-
system_time_to_timestamp(rwc.decode(id.clone()).unwrap())
243+
system_time_to_timestamp(rwc.decode(&id).unwrap())
247244
== system_time_to_timestamp(current)
248245
);
249246
}
@@ -255,7 +252,7 @@ mod tests {
255252

256253
let current: SystemTime = SystemTime::now();
257254
let generated: GenerateResult = rwc.generate(current, None);
258-
let verified: VerifyResult = rwc.verify(generated.result.unwrap());
255+
let verified: VerifyResult = rwc.verify(&generated.result.unwrap());
259256

260257
assert!(verified.success == true);
261258
assert!(match verified.result {

package/CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
## 0.2.0 (2024-10-13)
2+
3+
### Breaking Changes
4+
5+
- Changes in accepted value type of `decode`:
6+
- `String` => `&str`
7+
- Changes in accepted value type of `verify`:
8+
- `String` => `&str`
9+
- Changes in accepted value type of `char_list` in `RowIDWithConfig`:
10+
- `String` => `&str`
11+
- Merge different error messages into `RowIDError` enum
12+
13+
### What's New
14+
15+
- Add different derives for different structs
16+
17+
### What's Changed
18+
19+
- Updates in documentation
20+
121
## 0.1.1 (2024-08-04)
222

323
### What's Changed

package/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rowid"
3-
version = "0.1.1"
3+
version = "0.2.0"
44
authors = ["Alpheus Tang"]
55
edition = "2021"
66
description = """
@@ -32,4 +32,4 @@ name = "rowid"
3232
path = "src/lib.rs"
3333

3434
[dependencies]
35-
rand = "0.8.5"
35+
rand = "~0.8.5"

package/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Or start a customization with the following code:
1818
use rowid::{RowIDWithConfig, RowIDWithConfigResult};
1919

2020
let rwc: RowIDWithConfigResult = RowIDWithConfig::new()
21-
.char_list("0123456789ABCDEFGHJKMNPQRSTVWXYZ".to_string())
21+
.char_list("0123456789ABCDEFGHJKMNPQRSTVWXYZ")
2222
.randomness_length(22)
2323
.done()
2424
.unwrap();

package/src/base/rowid.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use crate::functions::verify::{
2727
/// ```
2828
pub fn rowid() -> String {
2929
_rowid(RowIDOptions {
30-
char_list: CHAR_LIST.to_string(),
30+
char_list: CHAR_LIST,
3131
randomness_length: RANDOMNESS_LENGTH,
3232
})
3333
}
@@ -44,7 +44,7 @@ pub fn rowid() -> String {
4444
/// let encoded: String = encode(SystemTime::now()).unwrap();
4545
/// ```
4646
pub fn encode(system_time: SystemTime) -> io::Result<String> {
47-
_encode(EncodeOptions { char_list: CHAR_LIST.to_string(), system_time })
47+
_encode(EncodeOptions { char_list: CHAR_LIST, system_time })
4848
}
4949

5050
/// This function decodes the ID into a timestamp in milliseconds.
@@ -55,10 +55,10 @@ pub fn encode(system_time: SystemTime) -> io::Result<String> {
5555
/// use std::time::SystemTime;
5656
/// use rowid::decode;
5757
///
58-
/// let decoded: SystemTime = decode("ABC123".to_string()).unwrap();
58+
/// let decoded: SystemTime = decode("ABC123").unwrap();
5959
/// ```
60-
pub fn decode(encoded: String) -> io::Result<SystemTime> {
61-
_decode(DecodeOptions { char_list: CHAR_LIST.to_string(), encoded })
60+
pub fn decode(encoded: &str) -> io::Result<SystemTime> {
61+
_decode(DecodeOptions { char_list: CHAR_LIST, encoded })
6262
}
6363

6464
/// This function generates an ID based on the input.
@@ -77,7 +77,7 @@ pub fn generate(
7777
randomness_length: Option<usize>,
7878
) -> GenerateResult {
7979
_generate(GenerateOptions {
80-
char_list: CHAR_LIST.to_string(),
80+
char_list: CHAR_LIST,
8181
system_time,
8282
randomness_length: match randomness_length {
8383
| Some(l) => l,
@@ -93,10 +93,10 @@ pub fn generate(
9393
/// ```no_run
9494
/// use rowid::{verify, VerifyResult};
9595
///
96-
/// let result: VerifyResult = verify("ABC123".to_string());
96+
/// let result: VerifyResult = verify("ABC123");
9797
/// ```
98-
pub fn verify(encoded: String) -> VerifyResult {
99-
_verify(VerifyOptions { char_list: CHAR_LIST.to_string(), encoded })
98+
pub fn verify(encoded: &str) -> VerifyResult {
99+
_verify(VerifyOptions { char_list: CHAR_LIST, encoded })
100100
}
101101

102102
/// This function generates randomness.
@@ -110,7 +110,7 @@ pub fn verify(encoded: String) -> VerifyResult {
110110
/// ```
111111
pub fn get_randomness(randomness_length: usize) -> String {
112112
_get_randomness(GetRandomnessOptions {
113-
char_list: CHAR_LIST.to_string(),
113+
char_list: CHAR_LIST,
114114
randomness_length,
115115
})
116116
}

0 commit comments

Comments
 (0)