{"id":23407700,"url":"https://github.com/bestia-dev/rust02_workspace_and_testing","last_synced_at":"2025-04-09T00:49:14.136Z","repository":{"id":105012017,"uuid":"184697173","full_name":"bestia-dev/rust02_workspace_and_testing","owner":"bestia-dev","description":"Learning Rust - how to use workspace, binary, library and testing","archived":false,"fork":false,"pushed_at":"2025-03-29T15:58:36.000Z","size":61,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-03-29T16:30:21.404Z","etag":null,"topics":["obsolete","tutorial"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bestia-dev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-05-03T04:12:10.000Z","updated_at":"2025-03-29T15:58:39.000Z","dependencies_parsed_at":null,"dependency_job_id":"72e7c280-c42d-4683-b00d-011ac397e77f","html_url":"https://github.com/bestia-dev/rust02_workspace_and_testing","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bestia-dev%2Frust02_workspace_and_testing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bestia-dev%2Frust02_workspace_and_testing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bestia-dev%2Frust02_workspace_and_testing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bestia-dev%2Frust02_workspace_and_testing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bestia-dev","download_url":"https://codeload.github.com/bestia-dev/rust02_workspace_and_testing/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247953090,"owners_count":21023945,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["obsolete","tutorial"],"created_at":"2024-12-22T14:29:36.239Z","updated_at":"2025-04-09T00:49:14.130Z","avatar_url":"https://github.com/bestia-dev.png","language":"Rust","readme":"\u003c!-- markdownlint-disable MD041 --\u003e\n[//]: # (auto_md_to_doc_comments segment start A)\n\n# rust02_workspace_and_testing\n\n**Learning Rust - how to use workspace, binary, library and testing**  \n***version: 1.0  date: 2019-05-03 author: [bestia.dev](https://bestia.dev) repository: [GitHub](https://github.com/bestia-dev/rust02_workspace_and_testing)***  \n\n ![obsolete](https://img.shields.io/badge/obsolete-red)\n ![tutorial](https://img.shields.io/badge/tutorial-yellow)\n ![License](https://img.shields.io/badge/license-MIT-blue.svg)\n ![rust02_workspace_and_testing](https://bestia.dev/webpage_hit_counter/get_svg_image/543481533.svg)\n\nHashtags: #rustlang #tutorial  \nMy projects on Github are more like a tutorial than a finished product: [bestia-dev tutorials](https://github.com/bestia-dev/tutorials_rust_wasm).\n\n## OBSOLETE\n\nThis project is now 4 years old and it is obsolete.\nPlease follow this link to the updated version:\n\u003chttps://github.com/CRUSTDE-ContainerizedRustDevEnv\u003e\n\nThere is still some interesting information in this project, so I will not archive it. But I don't recommend to use it for working projects.\n\n## Workspace\n\nFor Rust Workspace is a group of projects developed together.  \nIt is easy to make a binary (main.rs, executable) project. But it is not good for testing.  \nIt is easy to make a library (lib.rs) but you can not run it.  \nWith a workplace I can split my application into one binary source code and one library source code. So I have the best of both worlds.  \nThe result is still just one executable file. That is a great thing with Rust.  \n\n## date_diff\n\nI want to make a simple CLI (console line interface) application that calculates date difference.  \nI need it to know how many days I am already on vacation.  \nI try to use all small caps and underscores for all the file/folder names because of the case sensitivity of Linux file system.  \n\n## GitHub and Git\n\nI pushed the code of this project to GitHub using Git. I believe you are now reading it from GitHub. I suppose you have Git already installed if you learned from my last project \u003chttps://github.com/bestia-dev/rust01_the_beginning\u003e.  \nCloning a GitHub repository to a local folder is super simple.  \nIn GitHub click on the `Clone or download` big green button. You can there copy the URL to your clipboard.  \nOpen a Command prompt. Go to the `/rustprojects` folder and type  \n`clone` and space and then paste the clipboard content with `Ctrl + v`  \nYes, the command prompt after years and years of right clicks now supports the ubiquitous `Ctrl + v`. In Linux bash you have still to use right click for this.  \nPress `Enter` to run it.  \nIt will clone the GitHub repository in a new subfolder.  \nBTW if you like you can install the Chrome extension \"GitHub Dark Theme\".  \n\n## Build and run\n\nGo into this subfolder:  \n\n```bash\ncd rust02_workspace_and_testing\n```  \n\nExecute the command to build and run with parameters  \n\n```bash\ncargo run -- 20190909 20190808\n```  \n\nYou can also do it in two separate steps  \n\n```bash\ncargo build\ntarget\\debug\\date_diff.exe 20190909 20190808\n```  \n\n## Source code\n\nTo understand the result let's have a look at the source code in VSCode.  \n`File - Open folder - c:\\Users\\Luciano\\RustProjects\\rust02_workspace_and_testing\\`  \nYou will use your username here.  \nYou will see that VSCode has a command `Open Workspace`, but I think it is for another type of Workspace, not the Rust Workspace.  \nLet's open the file `/date_diff/src/main.rs`  \nI verbosely commented the code so it is most instructional.  \nNow open the `/date_diff_lib/lib.rs`  \nIt has a `test` region and only one true public function.  \nAll is heavy commented.  \n  \n## Linux\n\nWe want the same code to be compiled for Linux.  \nOpen the `Debian bash` of WSL. You know that from the first tutorial.  \n`cd r` then press Tab key and it will suggest `rustprojects` probably.  \n`cd rust02` then press Tab key and it will suggest `rust02_workspace_and_testing/` probably.  \nIt is practical to learn this Tab key suggestions instead of typing long file/folder names.  \n\n```bash\ncargo build  \ntarget/debug/date_diff 20190909 20190808\n```  \n\nThe result must be the same as in windows.  \n  \n## Cargo.toml\n\nThe file `Cargo.toml` is the configuration file for the Cargo builder tool.  \nIt is inside every Rust project or workspace.  \nIf we look inside the first `/Cargo.toml` we will see that the workspace has 2 members.  \nThe `date_diff` project has its own `Cargo.toml`. It contains package metadata and dependencies.  \nThe `date_diff_lib` project `Cargo.toml` file contains only package metadata.  \nThe `Better TOML` extension for VSCode is useful for this syntax in general.  \nThe VSCode extension `crates` is useful for working with dependencies in `Cargo.toml`.  \nDependencies are by default downloaded from the standard Rust crate repository `crates.io`.  \nFor local dependencies use the syntax like this `{ path = \"../date_diff_lib\" }`.  \n\n## Testing\n\nIn the workspace folder run  \n\n```bash\ncargo test\n```  \n\nIt will execute all tests that are included in the source code.  \nFind them in `lib.rs` in the module `mod tests`.  \nTest are nothing else then normal functions. They are just decorated with  \n`#[test]`  \nto let the Cargo tool understand they are tests.  \nYou can also write tests inside function doc comments. This special comments have three slashes and are located before the function declaration. They are used to generate the documentation. If the test passes it can mean, the documentation is up to date.  \n\u003chttps://learning-rust.github.io/docs/a5.comments_and_documenting_the_code.html\u003e  \n\n## VSCode\n\nThere is a lot of typing in English so I would like to have a spellchecker. I found the VSCode extension `Spell Right`. When editing a text in the right corner down of the status bar there is an `open eye`. Click on it to choose the language.  \n\n## Next projects\n\n\u003chttps://github.com/bestia-dev/mem1\u003e  \n  \n## References\n\n\u003chttps://doc.rust-lang.org/stable/book/\u003e  \n\n## Open-source and free as a beer\n\nMy open-source projects are free as a beer (MIT license).  \nI just love programming.  \nBut I need also to drink. If you find my projects and tutorials helpful, please buy me a beer by donating to my [PayPal](https://paypal.me/LucianoBestia).  \nYou know the price of a beer in your local bar ;-)  \nSo I can drink a free beer for your health :-)  \n[Na zdravje!](https://translate.google.com/?hl=en\u0026sl=sl\u0026tl=en\u0026text=Na%20zdravje\u0026op=translate) [Alla salute!](https://dictionary.cambridge.org/dictionary/italian-english/alla-salute) [Prost!](https://dictionary.cambridge.org/dictionary/german-english/prost) [Nazdravlje!](https://matadornetwork.com/nights/how-to-say-cheers-in-50-languages/) 🍻\n\n[//bestia.dev](https://bestia.dev)  \n[//github.com/bestia-dev](https://github.com/bestia-dev)  \n[//bestiadev.substack.com](https://bestiadev.substack.com)  \n[//youtube.com/@bestia-dev-tutorials](https://youtube.com/@bestia-dev-tutorials)  \n\n[//]: # (auto_md_to_doc_comments segment end A)\n","funding_links":["https://paypal.me/LucianoBestia"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbestia-dev%2Frust02_workspace_and_testing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbestia-dev%2Frust02_workspace_and_testing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbestia-dev%2Frust02_workspace_and_testing/lists"}