{"id":17084388,"url":"https://github.com/niklasf/rust-pgn-reader","last_synced_at":"2025-04-12T16:42:27.047Z","repository":{"id":25688247,"uuid":"102883569","full_name":"niklasf/rust-pgn-reader","owner":"niklasf","description":"Fast non-allocating and streaming reader for chess games in PGN notation","archived":false,"fork":false,"pushed_at":"2024-12-11T22:14:07.000Z","size":271,"stargazers_count":69,"open_issues_count":13,"forks_count":20,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-03T19:13:23.038Z","etag":null,"topics":["chess","pgn","rust"],"latest_commit_sha":null,"homepage":"https://docs.rs/pgn-reader","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/niklasf.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"COPYING","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},"funding":{"github":"niklasf"}},"created_at":"2017-09-08T16:45:09.000Z","updated_at":"2025-03-26T21:44:17.000Z","dependencies_parsed_at":"2024-12-31T05:11:32.269Z","dependency_job_id":"346c6269-fb29-45c6-a398-391b90fafa2f","html_url":"https://github.com/niklasf/rust-pgn-reader","commit_stats":{"total_commits":228,"total_committers":7,"mean_commits":32.57142857142857,"dds":"0.030701754385964897","last_synced_commit":"0678323c95b823be22757bb949d5c30b16641687"},"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/niklasf%2Frust-pgn-reader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/niklasf%2Frust-pgn-reader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/niklasf%2Frust-pgn-reader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/niklasf%2Frust-pgn-reader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/niklasf","download_url":"https://codeload.github.com/niklasf/rust-pgn-reader/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248599294,"owners_count":21131257,"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":["chess","pgn","rust"],"created_at":"2024-10-14T13:06:58.180Z","updated_at":"2025-04-12T16:42:27.011Z","avatar_url":"https://github.com/niklasf.png","language":"Rust","funding_links":["https://github.com/sponsors/niklasf"],"categories":[],"sub_categories":[],"readme":"pgn-reader\n==========\n\nA fast non-allocating and streaming reader for chess games in PGN notation,\nas a Rust library.\n\n[![Build Status](https://travis-ci.org/niklasf/rust-pgn-reader.svg?branch=master)](https://travis-ci.org/niklasf/rust-pgn-reader)\n[![crates.io](https://img.shields.io/crates/v/pgn-reader.svg)](https://crates.io/crates/pgn-reader)\n[![docs.rs](https://docs.rs/pgn-reader/badge.svg)](https://docs.rs/pgn-reader)\n\nIntroduction\n------------\n\n`Reader` parses games and calls methods of a user provided `Visitor`.\nImplementing custom visitors allows for maximum flexibility:\n\n* The reader itself does not allocate (besides a single fixed-size buffer).\n  The visitor can decide if and how to represent games in memory.\n* The reader does not validate move legality.\n  This allows implementing support for custom chess variants,\n  or delaying move validation.\n* The visitor can signal to the reader that it does not care about a game or\n  variation.\n\nExample\n-------\n\nA visitor that counts the number of syntactically valid moves in the\nmainline of each game.\n\n```rust\nuse std::io;\nuse pgn_reader::{Visitor, Skip, BufferedReader, SanPlus};\n\nstruct MoveCounter {\n    moves: usize,\n}\n\nimpl MoveCounter {\n    fn new() -\u003e MoveCounter {\n        MoveCounter { moves: 0 }\n    }\n}\n\nimpl Visitor for MoveCounter {\n    type Result = usize;\n\n    fn begin_game(\u0026mut self) {\n        self.moves = 0;\n    }\n\n    fn san(\u0026mut self, _san_plus: SanPlus) {\n        self.moves += 1;\n    }\n\n    fn begin_variation(\u0026mut self) -\u003e Skip {\n        Skip(true) // stay in the mainline\n    }\n\n    fn end_game(\u0026mut self) -\u003e Self::Result {\n        self.moves\n    }\n}\n\nfn main() -\u003e io::Result\u003c()\u003e {\n    let pgn = b\"1. e4 e5 2. Nf3 (2. f4)\n                { game paused due to bad weather }\n                2... Nf6 *\";\n\n    let mut reader = BufferedReader::new_cursor(\u0026pgn[..]);\n\n    let mut counter = MoveCounter::new();\n    let moves = reader.read_game(\u0026mut counter)?;\n\n    assert_eq!(moves, Some(4));\n    Ok(())\n}\n```\n\nDocumentation\n-------------\n\n[Read the documentation](https://docs.rs/pgn-reader)\n\nState of the library\n--------------------\n\nThe API could be cleaner and performance may have regressed slightly compared\nto the `mmap` based approach from old versions\n([#12](https://github.com/niklasf/rust-pgn-reader/issues/12)).\nThis needs some attention. Until I get around to it, I am doing only\nminimal maintenance, following `shakmaty` as required.\n\nNonetheless, it is probably still one of the fastest PGN parsers around.\n\nBenchmarks (v0.12.0)\n--------------------\n\nRun with [lichess_db_standard_rated_2018-10.pgn](https://database.lichess.org/standard/lichess_db_standard_rated_2018-10.pgn.bz2) (24,784,600 games, 52,750 MB uncompressed) on an SSD (Samsung 850), Intel i7-6850K CPU @ 3.60 GHz:\n\nBenchmark | Time | Throughput\n--- | --- | ---\nexamples/stats.rs | 111.9s | 471.4 MB/s\nexamples/validate.rs | 237.1s | 222.5 MB/s\nexamples/parallel_validate.rs | 148.6s | 355.0 MB/s\n[`scoutfish make`](https://github.com/mcostalba/scoutfish) | 269.2s | 196.0 MB/s\n`grep -F \"[Event \" -c` | 39.2s | 1345.7 MB/s\n\n`examples/stats.rs` with compressed files:\n\nCompression | File size | Time | Throughput\n--- | --- | --- | ---\n*none* | 52,750 MB | 111.9s | 471.4 MB/s\nbz2 | 6,226 MB | 1263.1s | 4.9 MB/s\nxz | 6,989 MB | 495.9s | 14.1 MB/s\ngz | 10,627 MB | 335.7s | 31.7 MB/s\nlz4 | 16,428 MB | 180.0s | 91.3 MB/s\n\nLicense\n-------\n\npgn-reader is licensed under the GPL-3.0 (or any later version at your option).\nSee the COPYING file for the full license text.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fniklasf%2Frust-pgn-reader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fniklasf%2Frust-pgn-reader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fniklasf%2Frust-pgn-reader/lists"}