Skip to content

Commit

Permalink
add license
Browse files Browse the repository at this point in the history
  • Loading branch information
chemyl committed Nov 19, 2024
1 parent a5f5c49 commit a5976dc
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 11 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Anatolii Maltsev

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
### Basic project of interpreting Rust code into a web application using WebAssembly

![Rust Version](https://img.shields.io/badge/rust-1.82.0%20-green)
![wasm-bindgen Version](https://img.shields.io/badge/wasm_bingen-0.2.95%20-orange)
![serde Version](https://img.shields.io/badge/wasm_test-0.3%20-orange)
![Build Status](https://github.com/chemyl/tax_app_webassembly/actions/workflows/rust.yml/badge.svg)

- create library crate -> `cargo new project --lib`
- add dependency to `cargo.toml`-> `wasm-bindgen = "0.2.+"`
- add library annotation for compiler ->` [lib] crate-type = ["cdylib"]`
- include wasm prelude inside `lib.rs`
- create public function with necessary logic in `lib.rs`
- create `index.html` file with simple html template with header and `style.css` inclusion in project root
- create `styles.css` style file
- create skeleton inside `index.html` and extend `script block` with logic of working with wasm inclusion
- install wasm-pack -> `cargo install wasm-pack`
- build project with wasm-pack -> `wasm-pack build --target web`
- include web server -> `npm install -g http-server`
- start server in project root folder -> `http-server .`
- switch to `localhost`

![launcher window](https://github.com/chemyl/tax_app_webassembly/blob/master/img.png)
![launcher window](https://github.com/chemyl/tax_app_webassembly/blob/master/example.gif)
Binary file added example.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed img.png
Binary file not shown.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<body>

<h1>Tax Calculator </h1>
<label for="income"> Income:</label>
<label for="income"> USD Income:</label>
<input type="number" id="income" name="income" min="0">
<button id="calculateButton"> Calculate Tax</button>
<p id="result"></p>
Expand Down
7 changes: 4 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ use wasm_bindgen::prelude::*;
#[wasm_bindgen]
pub fn calculate_tax(income: f64) -> f64 {
let mut tax = 0.0;

if income <= 9875.0 {
if income < 0.0 {
tax = 0.0;
} else if income <= 9875.0 {
tax = income * 0.10;
} else if income <= 40125.0 {
tax = 987.5 + (income - 9875.0) * 0.12;
Expand All @@ -26,7 +27,7 @@ pub fn calculate_tax(income: f64) -> f64 {

#[cfg(test)]
mod tests {
use super::*;
use crate::calculate_tax;

#[test]
fn test_calculate_tax() {
Expand Down

0 comments on commit a5976dc

Please sign in to comment.