{"id":18160530,"url":"https://github.com/ventgrey/scanrs","last_synced_at":"2025-05-07T08:44:53.705Z","repository":{"id":48693195,"uuid":"223277474","full_name":"VentGrey/scanrs","owner":"VentGrey","description":"A simple Rust Library to easily process std input.","archived":false,"fork":false,"pushed_at":"2023-02-26T10:14:41.000Z","size":45,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-06T23:47:07.593Z","etag":null,"topics":["crates","input","read","rust","rust-lang","scanf","std"],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/VentGrey.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}},"created_at":"2019-11-21T22:33:18.000Z","updated_at":"2024-09-19T20:43:15.000Z","dependencies_parsed_at":"2024-01-05T23:56:48.675Z","dependency_job_id":null,"html_url":"https://github.com/VentGrey/scanrs","commit_stats":{"total_commits":47,"total_committers":4,"mean_commits":11.75,"dds":"0.14893617021276595","last_synced_commit":"e3086c3175c4e37bdfa2c9568d1a3b1aed17153f"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VentGrey%2Fscanrs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VentGrey%2Fscanrs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VentGrey%2Fscanrs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VentGrey%2Fscanrs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/VentGrey","download_url":"https://codeload.github.com/VentGrey/scanrs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222688193,"owners_count":17023296,"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":["crates","input","read","rust","rust-lang","scanf","std"],"created_at":"2024-11-02T08:08:32.245Z","updated_at":"2024-11-02T08:08:32.626Z","avatar_url":"https://github.com/VentGrey.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# scanrs\n\nA dead-simple Rust Library to easily process std input. No dependencies, no strange functionalities, not even useful enough. You can always copy-paste the code inside `src/lib.rs`.\n\n## What is it?\n\nThis crate was a little inspired by this, so it won't have any dependencies\nbesides the standard library, anything extra should be done by hand or\ncherrypicked to avoid bloating something this simple.\n\nhttps://www.reddit.com/r/rust/comments/dy365h/only_one_wish_for_rust_2020/\n\n\u003e 2023 update: I've realized the terrible mistake I've made by publishing this. Adding up to the dependency-hell problem because devs are independent-no-more. I'll keep maintaining this \"feature complete\" crate. However, I plead to you, please, don't be an npm user and get a library for dead-simple things :) checkout [rust easy snippets for this](https://github.com/VentGrey/rust-easy-snippets)\n\nscanrs is a small working rust crate that makes handling user input\neasier.\n\nRust has a rather ~~\"weird\"~~ verbose way to read std input, even though asking for user\ninput inside terminal applications is a little outdated. If you cannot rely on the command-line arguments for reliable input, this crate can prove itself useful.\n\nThe other case-scenario in my head is to use this to aid new rustaceans to ask for a proper\ninput, sadly doing this in rust results in long lines of text and the end program turns very verbose (not really).\n\nThis library just attempts to make reading standard primitive types (and two more cases) easier which\nmakes it faster, simple to understand and lightweight.\n\n## How to use it?\n\nThis crate doesn't have much science behind it, to it's fairly simple to use,\nyou just assign a variable and set it's value to the result of the function you wish.\n\n\n### One way of reading user input in rust:\n\nOne simple way to read user input in rust is by playing a little with error\nhandling (or using a straight `unwrap` instead).\n\n``` rust\nlet mut number = String::new();\n\nio::stdin().read_line(\u0026mut number).expect(\"IO Failure\");\n\nlet number: f64 = match number.trim().parse() {\n    Ok(num) =\u003e num,\n    Err(_) =\u003e panic!(\"Not a number!\"),\n};\n```\n\nor\n\n``` rust\nlet mut number = String::new();\nio::stdin().read_line(\u0026mut number).expect(\"IO Failure\");\n\nmatch input.trim().parse() {\n    Ok(number) =\u003e number,\n    Err(_) =\u003e panic!(\"Invalid input. Please enter a valid number.\"),\n}\n\n```\n\nHowever this turns a little verbose when you need to read multiple variables, so\nyou can use this crate instead.\n\n``` rust\nuse scanrs::scann;\n\nfn main() {\n    println!(\"Please input a number\");\n    let num = scann();\n    println!(\"You entered {}\", num);\n}\n```\n\n## What kind of primitive types can it handle?\n\nCurrent functions available:\n\n* `scann`: Reads a number from stdin.\n* `scanvec`: Scans a whitespace separated list of elements\n* `scanln`: Scans a String\n\n## TODO: \n- [ ] ~~Allow users to customize input message.~~ - Dimmed as bloatware\n- [ ] Allow users to customize the function error message without introducing a breaking change.\n- [ ] ~~Make this crate colored to send fancy errors.~~ - Dimmed as bloatware\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fventgrey%2Fscanrs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fventgrey%2Fscanrs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fventgrey%2Fscanrs/lists"}