{"id":21586088,"url":"https://github.com/magiclen/scanner-rust","last_synced_at":"2025-04-10T20:20:30.400Z","repository":{"id":57666319,"uuid":"177867722","full_name":"magiclen/scanner-rust","owner":"magiclen","description":"Simple text scanners which can parse primitive types and strings using UTF-8 or ASCII.","archived":false,"fork":false,"pushed_at":"2023-11-11T05:11:29.000Z","size":80,"stargazers_count":5,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-09-17T14:58:25.594Z","etag":null,"topics":["rust","scanner"],"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/magiclen.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-03-26T20:58:49.000Z","updated_at":"2024-03-06T18:01:39.000Z","dependencies_parsed_at":"2024-11-24T18:01:11.441Z","dependency_job_id":null,"html_url":"https://github.com/magiclen/scanner-rust","commit_stats":{"total_commits":50,"total_committers":1,"mean_commits":50.0,"dds":0.0,"last_synced_commit":"4c1086613e06157f4308cafc73089d6303c5e187"},"previous_names":[],"tags_count":35,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magiclen%2Fscanner-rust","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magiclen%2Fscanner-rust/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magiclen%2Fscanner-rust/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magiclen%2Fscanner-rust/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/magiclen","download_url":"https://codeload.github.com/magiclen/scanner-rust/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248289812,"owners_count":21078921,"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":["rust","scanner"],"created_at":"2024-11-24T15:12:39.052Z","updated_at":"2025-04-10T20:20:30.385Z","avatar_url":"https://github.com/magiclen.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"Scanner\n====================\n\n[![CI](https://github.com/magiclen/scanner-rust/actions/workflows/ci.yml/badge.svg)](https://github.com/magiclen/scanner-rust/actions/workflows/ci.yml)\n\nThis crate provides Java-like Scanners which can parse primitive types and strings using UTF-8 or ASCII.\n\n### Scan a stream\n\n`Scanner` or `ScannerAscii` can be used for reading strings or raw data from a stream.\n\n```rust\nuse std::io::{self, Write};\n\nuse scanner_rust::ScannerAscii;\n\nprint!(\"Please input two integers, a and b: \");\nio::stdout().flush().unwrap();\n\nlet mut sc = ScannerAscii::new(io::stdin());\n\nlet a = {\n    loop {\n        match sc.next_isize() {\n            Ok(i) =\u003e break i.unwrap_or(0),\n            Err(_) =\u003e {\n                print!(\"Re-input a and b: \");\n                io::stdout().flush().unwrap();\n            }\n        }\n    }\n};\n\nlet b = {\n    loop {\n        match sc.next_isize() {\n            Ok(i) =\u003e break i.unwrap_or(0),\n            Err(_) =\u003e {\n                print!(\"Re-input b: \");\n                io::stdout().flush().unwrap();\n            }\n        }\n    }\n};\n\nprintln!(\"{} + {} = {}\", a, b, a + b);\n```\n\nBesides, the `drop_next` and `drop_next_line` methods are useful when you want to skip some data.\n\nThe default buffer size is 256 bytes. If you want to change that, you can use the `new2` associated function or the `scan_path2` associated function and define a length explicitly to create an instance of the above structs.\n\nFor example, to change the buffer size to 64 bytes,\n\n```rust\nuse scanner_rust::generic_array::typenum::U64;\nuse scanner_rust::Scanner;\n\nlet mut sc: Scanner\u003c_, U64\u003e = Scanner::scan_path2(\"Cargo.toml\").unwrap();\n```\n\n### Scan a string slice (`\u0026str`)\n\n`ScannerStr` can be used for reading strings from a string slice.\n\n```rust\nuse std::io::{self, Write};\n\nuse scanner_rust::ScannerStr;\n\nlet mut sc = ScannerStr::new(\" 123   456.7    \\t\\r\\n\\n c中文字\\n\\tHello world!\");\n\nassert_eq!(Some(123), sc.next_u8().unwrap());\nassert_eq!(Some(456.7), sc.next_f64().unwrap());\nassert_eq!(Some(' '), sc.next_char().unwrap());\nassert_eq!(Some(' '), sc.next_char().unwrap());\nassert_eq!(true, sc.skip_whitespaces().unwrap());\nassert_eq!(Some('c'), sc.next_char().unwrap());\nassert_eq!(Some(\"中文字\"), sc.next_line().unwrap());\nassert_eq!(Some(\"\\tHello world!\".into()), sc.next_line().unwrap());\nassert_eq!(None, sc.next_line().unwrap());\n```\n\n### Scan a u8 slice\n\n`ScannerU8Slice` or `ScannerU8SliceAscii` can be used for reading raw data from a `u8` slice.\n\n```rust\nuse std::io::{self, Write};\n\nuse scanner_rust::ScannerU8Slice;\n\nlet mut sc = ScannerU8Slice::new(\" 123   456.7    \\t\\r\\n\\n c中文字\\n\\tHello world!\".as_bytes());\n\nassert_eq!(Some(123), sc.next_u8().unwrap());\nassert_eq!(Some(456.7), sc.next_f64().unwrap());\nassert_eq!(Some(' '), sc.next_char().unwrap());\nassert_eq!(Some(' '), sc.next_char().unwrap());\nassert_eq!(true, sc.skip_whitespaces().unwrap());\nassert_eq!(Some('c'), sc.next_char().unwrap());\nassert_eq!(Some(\"中文字\".as_bytes()), sc.next_line().unwrap());\nassert_eq!(Some(\"\\tHello world!\".as_bytes()), sc.next_line().unwrap());\nassert_eq!(None, sc.next_line().unwrap());\n```\n\n## Crates.io\n\nhttps://crates.io/crates/scanner-rust\n\n## Documentation\n\nhttps://docs.rs/scanner-rust\n\n## License\n\n[MIT](LICENSE)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmagiclen%2Fscanner-rust","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmagiclen%2Fscanner-rust","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmagiclen%2Fscanner-rust/lists"}