Skip to content

Commit a4c94a2

Browse files
committed
Init.
0 parents  commit a4c94a2

File tree

12 files changed

+591
-0
lines changed

12 files changed

+591
-0
lines changed

.github/workflows/rust.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
on: [push]
2+
name: Luhny.rs CI
3+
jobs:
4+
build_and_test:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- uses: actions/checkout@v2
8+
- uses: actions-rs/toolchain@v1
9+
with:
10+
toolchain: stable
11+
12+
- name: "Run tests."
13+
uses: actions-rs/cargo@v1
14+
with:
15+
command: test
16+
17+
- name: "Validate an IMEI number from the CLI. (true case)"
18+
uses: actions-rs/cargo@v1
19+
with:
20+
command: run
21+
args: -- -c 353879234252633
22+
23+
- name: "Validate an IMEI number from the CLI. (false case)"
24+
uses: actions-rs/cargo@v1
25+
with:
26+
command: run
27+
args: -- -c 353879234252634

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/target
2+
.DS_Store
3+
Cargo.lock

Cargo.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[package]
2+
name = "luhny"
3+
version = "0.1.0"
4+
edition = "2021"
5+
license-file = "LICENSE"
6+
author = ["Alyx Shang"]
7+
description= "A library and tool to validate unique device identifiers."
8+
homepage = "https://github.com/alyxshang/luhny.rs"
9+
repository = "https://github.com/alyxshang/luhny.rs"
10+
readme = "README.markdown"
11+
12+
[dependencies]
13+
cliply = { git = "https://github.com/alyxshang/cliply", tag = "v.0.1.0" }
14+
coutils = { git = "https://github.com/alyxshang/coutils", tag = "v.0.1.0" }
15+
16+
[profile.release]
17+
lto = true
18+
strip = true
19+
opt-level = "z"
20+
codegen-units = 1

LICENSE

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FAIR SOFTWARE LICENSE
2+
Version 1, September 3 2024
3+
4+
Copyright (C) 2024 Alyx Shang <https://alyxshang.boo>
5+
Anyone is permitted to copy and distribute verbatim copies
6+
of this license document, but changing it is not allowed.
7+
8+
A single author or authors of this project permit the following use of this project:
9+
10+
- 1.) Any entity is allowed to redistribute and modify this project.
11+
- 2.) If the project is modified in any way, the original author or original authors must to be credited.
12+
- 3.) Corporate entities ARE NOT permitted to use this project commercially or for patent use.
13+
14+
The following restrictions apply to this project:
15+
16+
- 1.) The original author or original authors are not liable for any warranty claims. Use of the project is at one's own risk.
17+
- 2.) The original author or original authors are not responsible for any consequences resulting from use of this project.
18+
- 3.) Any modified versions of this project or projects making use of this project must use this version of this license.

README.markdown

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# LUHNY.RS :iphone: :lock: :crab:
2+
3+
![GitHub CI](https://github.com/alyxshang/luhny.rs/actions/workflows/rust.yml/badge.svg)
4+
5+
***A library and tool to validate unique device identifiers. :iphone: :lock: :crab:***
6+
7+
## ABOUT :books:
8+
9+
## USAGE :hammer:
10+
11+
## CHANGELOG :black_nib:
12+
13+
### Version 0.1.0
14+
15+
- Initial release.
16+
- Upload to GitHub.
17+
18+
## NOTE :scroll:
19+
20+
- *Luhny.rs :iphone: :lock: :crab:* by *Alyx Shang :black_heart:*.
21+
- Licensed under the [FSL v1](https://github.com/alyxshang/fair-software-license).

src/lib.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
Luhny.rs by Alyx Shang.
3+
Licensed under the FSL v1.
4+
*/
5+
6+
/// Declaring the
7+
/// "modules"
8+
/// directory as a module.
9+
pub mod modules;
10+
11+
/// Re-exporting the
12+
/// module containing
13+
/// this crate's
14+
/// error-handling
15+
/// structure.
16+
pub use modules::err::*;
17+
18+
/// Re-exporting the
19+
/// module containing
20+
/// this crate's
21+
/// CLI.
22+
pub use modules::cli::*;
23+
24+
/// Re-exporting the
25+
/// module containing
26+
/// this crate's
27+
/// main APIs.
28+
pub use modules::luhny::*;

src/main.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
Luhny.rs by Alyx Shang.
3+
Licensed under the FSL v1.
4+
*/
5+
6+
/// Importing this crate's
7+
/// CLI function.
8+
use luhny::cli;
9+
10+
/// The main
11+
/// point of entry
12+
/// for the Rust compiler.
13+
fn main(){
14+
match cli(){
15+
Ok(res) => println!("{}", &res),
16+
Err(e) => eprintln!("{}", &e)
17+
};
18+
}

src/modules/cli.rs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
Luhny.rs by Alyx Shang.
3+
Licensed under the FSL v1.
4+
*/
5+
6+
/// Importing the "App"
7+
/// structure from the "cliply"
8+
/// crate to make a new CLI
9+
/// application.
10+
use cliply::App;
11+
12+
/// Importing the structure
13+
/// to catch and handle errors.
14+
use super::err::LuhnyErr;
15+
16+
/// Importing the function to validate
17+
/// an IMEI number.
18+
use super::luhny::validate_imei;
19+
20+
/// This function contains Luhny's CLI.
21+
/// A string or an error is returned.
22+
pub fn cli() -> Result<String,LuhnyErr> {
23+
let mut luhny: App = App::new(
24+
"Luhny",
25+
"Alyx Shang",
26+
"0.1.0"
27+
);
28+
luhny.add_arg("chk", "check the supplied IMEI number", &true);
29+
if luhny.version_is(){
30+
Ok(luhny.version_info())
31+
}
32+
else if luhny.help_is(){
33+
Ok(luhny.help_info())
34+
}
35+
else if luhny.arg_was_used("chk"){
36+
let imei: String = match luhny.get_arg_data("chk"){
37+
Ok(imei) => imei,
38+
Err(e) => return Err::<String,LuhnyErr>(LuhnyErr::new(&e.to_string()))
39+
};
40+
let validation: bool = match validate_imei(&imei){
41+
Ok(validation) => validation,
42+
Err(e) => return Err::<String,LuhnyErr>(LuhnyErr::new(&e.to_string()))
43+
};
44+
45+
if validation {
46+
let msg: String = format!("The IMEI number \"{}\" is valid.", imei);
47+
Ok(msg)
48+
}
49+
else {
50+
let msg: String = format!("The IMEI number \"{}\" is not valid.", imei);
51+
Ok(msg)
52+
}
53+
}
54+
else {
55+
Err::<String,LuhnyErr>(LuhnyErr::new(&luhny.help_info()))
56+
}
57+
}

src/modules/err.rs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
Luhny.rs by Alyx Shang.
3+
Licensed under the FSL v1.
4+
*/
5+
6+
/// Importing the standard
7+
/// "Result" enum.
8+
use std::fmt::Result;
9+
10+
/// Importing the standard
11+
/// "Display" trait.
12+
use std::fmt::Display;
13+
14+
/// Importing the standard
15+
/// "Error" trait.
16+
use std::error::Error;
17+
18+
/// Importing the standard
19+
/// "Formatter" trait.
20+
use std::fmt::Formatter;
21+
22+
/// A data structure for
23+
/// storing and handling errors.
24+
#[derive(Clone,Eq,PartialEq, Debug)]
25+
pub struct LuhnyErr {
26+
pub details: String
27+
}
28+
29+
/// Implements functions
30+
/// for the "LuhnyErr"
31+
/// structure.
32+
impl LuhnyErr {
33+
34+
/// Implements a function to create
35+
/// a new instance of this data structure.
36+
pub fn new(details: &str) -> LuhnyErr {
37+
return LuhnyErr {
38+
details: details.to_owned()
39+
};
40+
}
41+
42+
/// Implements a function to return
43+
/// a string representation of this
44+
/// data structure.
45+
pub fn to_string(self) -> String {
46+
return self.details.to_string();
47+
}
48+
}
49+
50+
/// Implements the error trait.
51+
impl Error for LuhnyErr {
52+
fn description(&self) -> &str {
53+
&self.details
54+
}
55+
}
56+
57+
/// Implements the Display trait
58+
/// for the "LuhnyErr" structure.
59+
impl Display for LuhnyErr {
60+
fn fmt(&self, f: &mut Formatter) -> Result {
61+
return write!(f,"{}",self.details);
62+
}
63+
}

0 commit comments

Comments
 (0)