Skip to content

Commit

Permalink
Init.
Browse files Browse the repository at this point in the history
  • Loading branch information
alyxshang committed Sep 26, 2024
0 parents commit a4c94a2
Show file tree
Hide file tree
Showing 12 changed files with 591 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
on: [push]
name: Luhny.rs CI
jobs:
build_and_test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable

- name: "Run tests."
uses: actions-rs/cargo@v1
with:
command: test

- name: "Validate an IMEI number from the CLI. (true case)"
uses: actions-rs/cargo@v1
with:
command: run
args: -- -c 353879234252633

- name: "Validate an IMEI number from the CLI. (false case)"
uses: actions-rs/cargo@v1
with:
command: run
args: -- -c 353879234252634
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/target
.DS_Store
Cargo.lock
20 changes: 20 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "luhny"
version = "0.1.0"
edition = "2021"
license-file = "LICENSE"
author = ["Alyx Shang"]
description= "A library and tool to validate unique device identifiers."
homepage = "https://github.com/alyxshang/luhny.rs"
repository = "https://github.com/alyxshang/luhny.rs"
readme = "README.markdown"

[dependencies]
cliply = { git = "https://github.com/alyxshang/cliply", tag = "v.0.1.0" }
coutils = { git = "https://github.com/alyxshang/coutils", tag = "v.0.1.0" }

[profile.release]
lto = true
strip = true
opt-level = "z"
codegen-units = 1
18 changes: 18 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FAIR SOFTWARE LICENSE
Version 1, September 3 2024

Copyright (C) 2024 Alyx Shang <https://alyxshang.boo>
Anyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.

A single author or authors of this project permit the following use of this project:

- 1.) Any entity is allowed to redistribute and modify this project.
- 2.) If the project is modified in any way, the original author or original authors must to be credited.
- 3.) Corporate entities ARE NOT permitted to use this project commercially or for patent use.

The following restrictions apply to this project:

- 1.) The original author or original authors are not liable for any warranty claims. Use of the project is at one's own risk.
- 2.) The original author or original authors are not responsible for any consequences resulting from use of this project.
- 3.) Any modified versions of this project or projects making use of this project must use this version of this license.
21 changes: 21 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# LUHNY.RS :iphone: :lock: :crab:

![GitHub CI](https://github.com/alyxshang/luhny.rs/actions/workflows/rust.yml/badge.svg)

***A library and tool to validate unique device identifiers. :iphone: :lock: :crab:***

## ABOUT :books:

## USAGE :hammer:

## CHANGELOG :black_nib:

### Version 0.1.0

- Initial release.
- Upload to GitHub.

## NOTE :scroll:

- *Luhny.rs :iphone: :lock: :crab:* by *Alyx Shang :black_heart:*.
- Licensed under the [FSL v1](https://github.com/alyxshang/fair-software-license).
28 changes: 28 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
Luhny.rs by Alyx Shang.
Licensed under the FSL v1.
*/

/// Declaring the
/// "modules"
/// directory as a module.
pub mod modules;

/// Re-exporting the
/// module containing
/// this crate's
/// error-handling
/// structure.
pub use modules::err::*;

/// Re-exporting the
/// module containing
/// this crate's
/// CLI.
pub use modules::cli::*;

/// Re-exporting the
/// module containing
/// this crate's
/// main APIs.
pub use modules::luhny::*;
18 changes: 18 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
Luhny.rs by Alyx Shang.
Licensed under the FSL v1.
*/

/// Importing this crate's
/// CLI function.
use luhny::cli;

/// The main
/// point of entry
/// for the Rust compiler.
fn main(){
match cli(){
Ok(res) => println!("{}", &res),
Err(e) => eprintln!("{}", &e)
};
}
57 changes: 57 additions & 0 deletions src/modules/cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
Luhny.rs by Alyx Shang.
Licensed under the FSL v1.
*/

/// Importing the "App"
/// structure from the "cliply"
/// crate to make a new CLI
/// application.
use cliply::App;

/// Importing the structure
/// to catch and handle errors.
use super::err::LuhnyErr;

/// Importing the function to validate
/// an IMEI number.
use super::luhny::validate_imei;

/// This function contains Luhny's CLI.
/// A string or an error is returned.
pub fn cli() -> Result<String,LuhnyErr> {
let mut luhny: App = App::new(
"Luhny",
"Alyx Shang",
"0.1.0"
);
luhny.add_arg("chk", "check the supplied IMEI number", &true);
if luhny.version_is(){
Ok(luhny.version_info())
}
else if luhny.help_is(){
Ok(luhny.help_info())
}
else if luhny.arg_was_used("chk"){
let imei: String = match luhny.get_arg_data("chk"){
Ok(imei) => imei,
Err(e) => return Err::<String,LuhnyErr>(LuhnyErr::new(&e.to_string()))
};
let validation: bool = match validate_imei(&imei){
Ok(validation) => validation,
Err(e) => return Err::<String,LuhnyErr>(LuhnyErr::new(&e.to_string()))
};

if validation {
let msg: String = format!("The IMEI number \"{}\" is valid.", imei);
Ok(msg)
}
else {
let msg: String = format!("The IMEI number \"{}\" is not valid.", imei);
Ok(msg)
}
}
else {
Err::<String,LuhnyErr>(LuhnyErr::new(&luhny.help_info()))
}
}
63 changes: 63 additions & 0 deletions src/modules/err.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
Luhny.rs by Alyx Shang.
Licensed under the FSL v1.
*/

/// Importing the standard
/// "Result" enum.
use std::fmt::Result;

/// Importing the standard
/// "Display" trait.
use std::fmt::Display;

/// Importing the standard
/// "Error" trait.
use std::error::Error;

/// Importing the standard
/// "Formatter" trait.
use std::fmt::Formatter;

/// A data structure for
/// storing and handling errors.
#[derive(Clone,Eq,PartialEq, Debug)]
pub struct LuhnyErr {
pub details: String
}

/// Implements functions
/// for the "LuhnyErr"
/// structure.
impl LuhnyErr {

/// Implements a function to create
/// a new instance of this data structure.
pub fn new(details: &str) -> LuhnyErr {
return LuhnyErr {
details: details.to_owned()
};
}

/// Implements a function to return
/// a string representation of this
/// data structure.
pub fn to_string(self) -> String {
return self.details.to_string();
}
}

/// Implements the error trait.
impl Error for LuhnyErr {
fn description(&self) -> &str {
&self.details
}
}

/// Implements the Display trait
/// for the "LuhnyErr" structure.
impl Display for LuhnyErr {
fn fmt(&self, f: &mut Formatter) -> Result {
return write!(f,"{}",self.details);
}
}
Loading

0 comments on commit a4c94a2

Please sign in to comment.