{"id":17929231,"url":"https://github.com/heaths/ordinal-rs","last_synced_at":"2025-08-15T13:32:53.866Z","repository":{"id":259108589,"uuid":"874627314","full_name":"heaths/ordinal-rs","owner":"heaths","description":"Format ordinals in Rust","archived":false,"fork":false,"pushed_at":"2024-12-01T00:34:00.000Z","size":76,"stargazers_count":1,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-01T01:23:58.929Z","etag":null,"topics":["ordinals","performance"],"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/heaths.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","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":"2024-10-18T07:09:16.000Z","updated_at":"2024-12-01T00:34:03.000Z","dependencies_parsed_at":"2024-11-13T08:35:37.122Z","dependency_job_id":null,"html_url":"https://github.com/heaths/ordinal-rs","commit_stats":null,"previous_names":["heaths/ordinal-rs"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heaths%2Fordinal-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heaths%2Fordinal-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heaths%2Fordinal-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heaths%2Fordinal-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/heaths","download_url":"https://codeload.github.com/heaths/ordinal-rs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229916543,"owners_count":18144165,"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":["ordinals","performance"],"created_at":"2024-10-28T21:08:14.268Z","updated_at":"2025-08-15T13:32:53.454Z","avatar_url":"https://github.com/heaths.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Ordinal formatting\n\nFormat numbers as ordinals efficiently.\nYou can get the ordinal suffix e.g., \"st\", \"nd\", \"rd\", or \"th\" without allocations.\n\n## Examples\n\nFormat a number as an ordinal, allocating a new `String`:\n\n```rust\nuse ordinal::ToOrdinal as _;\nassert_eq!(12.to_ordinal_string(), \"12th\");\n```\n\nGet a number representing an ordinal you can use with comparisons and formatting.\n\n```rust\nuse ordinal::ToOrdinal as _;\nlet n = 12.to_ordinal();\nassert_eq!(*n, 12);\nassert_eq!(format!(\"{n}\"), \"12th\");\n```\n\n## Features\n\n* **std**: (default) all functionality enabled.\n* **alloc**: (default; enabled by **std**) all functionality enabled.\n\nThis crate supports `no_std`, though functionality is limited. If you disable default features, `no_std` will be enabled.\nYou can optionally add feature `alloc` (enabled by default with `std`) to enable all functionality without requiring `std`.\n\n```bash\ncargo add ordinal-trait --no-default-features --features alloc\n```\n\n## Performance\n\nCompared to most other implementations that allocate a string just to check the last one or two characters, this implementation is much faster and does not allocate a string.\n\n![violin plot](docs/suffix_violin_plot.svg)\n\nFormatting ordinals builds on this strategy and is faster than most other implementations:\n\n![violin plot](docs/fmt_violin_plot.svg)\n\nTo [compare measurements](https://bheisler.github.io/criterion.rs/book/user_guide/command_line_options.html#baselines) across branches:\n\n```bash\ngit checkout main\ncargo bench -- --save-baseline main\n\ngit checkout feature\ncargo bench -- --baseline main\n```\n\n## Memory profiling\n\nCriterion does not support memory profiling as of 0.5.1; however, I have implemented a simple solution using a global\nallocator. When run with `--profile-time \u003cnumber of seconds\u003e`, the total number of bytes allocated from the heap will\nbe written to the terminal in kibibytes. This may include heap allocations for Criterion itself, but should be limited\nto just before and after each benchmark.\n\n```bash\ncargo bench -- suffix --profile-time 3\n```\n\nWould print something like:\n\n```text\nBenchmarking suffix/ordinal/1: Profiling for 3.0000 s; allocated 0 KiB\nBenchmarking suffix/ordinal/1: Complete (Analysis Disabled)\nBenchmarking suffix/ordinal@0.3.2/1: Profiling for 3.0000 s; allocated 958,951 KiB\nBenchmarking suffix/ordinal@0.3.2/1: Complete (Analysis Disabled)\nBenchmarking suffix/ordinal-type/1: Profiling for 3.0000 s; allocated 949,659 KiB\nBenchmarking suffix/ordinal-type/1: Complete (Analysis Disabled)\n...\n```\n\n## History\n\nThis crate was previously published as [`ordinal-trait`](https://crates.io/crates/ordinal-trait) to format numbers efficiently.\nAfter coming across [gleich/ordinal#3](https://github.com/gleich/ordinal/pull/3) I offered to make mine compatible and maintain\nmine as [`ordinal`](https://crates.io/crates/ordinal). Thanks to [@dtolnay](https://github.com/dtolnay) for creating `ordinal`\nand [@gleich](https://github.com/gleich) for previously maintaining it.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fheaths%2Fordinal-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fheaths%2Fordinal-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fheaths%2Fordinal-rs/lists"}