{"id":23672039,"url":"https://github.com/fengalin/option-operations","last_synced_at":"2025-06-14T13:35:25.023Z","repository":{"id":39794543,"uuid":"412567074","full_name":"fengalin/option-operations","owner":"fengalin","description":"Traits and auto-implementations to improve arithmetic operations usability when dealing with `Option`s.","archived":false,"fork":false,"pushed_at":"2022-08-15T20:25:07.000Z","size":150,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-08-09T12:26:30.895Z","etag":null,"topics":["arithmetic","cmp","operations","option","ord","rust","traits"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fengalin.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-10-01T17:52:30.000Z","updated_at":"2024-06-06T10:47:59.000Z","dependencies_parsed_at":"2022-09-09T05:20:41.410Z","dependency_job_id":null,"html_url":"https://github.com/fengalin/option-operations","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fengalin%2Foption-operations","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fengalin%2Foption-operations/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fengalin%2Foption-operations/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fengalin%2Foption-operations/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fengalin","download_url":"https://codeload.github.com/fengalin/option-operations/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":231727106,"owners_count":18417391,"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":["arithmetic","cmp","operations","option","ord","rust","traits"],"created_at":"2024-12-29T10:36:07.789Z","updated_at":"2024-12-29T10:36:08.412Z","avatar_url":"https://github.com/fengalin.png","language":"Rust","readme":"# option-operations\n\n[![crates.io][Crate Logo]][Crate]\n[![Documentation][Doc Logo]][Doc]\n[![Build Status][CI Logo]][CI]\n[![MSRV][rustc Logo]][Crate]\n\n`option-operations` provides traits and auto-implementations to\nimprove arithmetic operations usability when dealing with `Option`s.\n\n## Example\n\nDealing with two `Option`s, can lead to verbose expressions:\n\n``` rust\nlet lhs = Some(1u64);\nlet rhs = Some(u64::MAX);\n\nassert_eq!(\n    lhs.zip(rhs).map(|(lhs, rhs)| lhs.saturating_add(rhs)),\n    Some(u64::MAX),\n);\n```\n\nThanks to the trait `OptionSaturatingAdd` we can write:\n\n``` rust\nassert_eq!(\n    lhs.opt_saturating_add(rhs),\n    Some(u64::MAX),\n);\n```\n\nThe trait can also be used with the inner type:\n\n``` rust\nassert_eq!(\n    lhs.opt_saturating_add(u64::MAX),\n    Some(u64::MAX),\n);\n\nassert_eq!(\n    1.opt_saturating_add(rhs),\n    Some(u64::MAX),\n);\n```\n\n## Alternative to `PartialOrd` for `Option\u003cT\u003e`\n\nAnother purpose is to workaround the `PartiaOrd` implementation\nfor `Option\u003cT\u003e`, which uses the declaration order of the variants\nfor `Option`. `None` appearing before `Some(_)`, it results in\nthe following behavior:\n\n``` rust\nlet some_0 = Some(0);\nlet none: Option\u003cu64\u003e = None;\n\nassert_eq!(none.partial_cmp(\u0026some_0), Some(Ordering::Less));\nassert_eq!(some_0.partial_cmp(\u0026none), Some(Ordering::Greater));\n```\n\nIn some cases, we might consider that `None` reflects a value which\nis not defined and thus can not be compared with `Some(_)`.\n\n``` rust\nassert_eq!(none.opt_cmp(\u0026some_0), None);\nassert_eq!(some_0.opt_cmp(\u0026none), None);\n```\n\nOf course, this is consistent with other usual comparisons:\n\n``` rust\nassert_eq!(none.opt_lt(\u0026some_0), None);\nassert_eq!(none.opt_min(\u0026some_0), None);\n```\n\n## LICENSE\n\nThis crate is licensed under either of\n\n * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or\n   http://www.apache.org/licenses/LICENSE-2.0)\n * MIT license ([LICENSE-MIT](LICENSE-MIT) or\n   http://opensource.org/licenses/MIT)\n\nat your option.\n\n\n[Crate]: https://crates.io/crates/option-operations\n[Crate Logo]: https://img.shields.io/crates/v/option-operations.svg\n\n[Doc]: https://docs.rs/option-operations\n[Doc Logo]: https://docs.rs/option-operations/badge.svg\n\n[CI]: https://github.com/fengalin/option-operations/actions/workflows/CI.yml\n[CI Logo]: https://github.com/fengalin/option-operations/workflows/CI/badge.svg\n\n[rustc Logo]: https://img.shields.io/badge/rust-1.53.0%2B-blue.svg?maxAge=3600\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffengalin%2Foption-operations","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffengalin%2Foption-operations","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffengalin%2Foption-operations/lists"}