{"id":17126390,"url":"https://github.com/kellpossible/commodity","last_synced_at":"2025-04-13T06:27:59.810Z","repository":{"id":57609216,"uuid":"244230263","full_name":"kellpossible/commodity","owner":"kellpossible","description":"A library for representing commodities/currencies in Rust","archived":false,"fork":false,"pushed_at":"2020-06-17T18:57:32.000Z","size":71,"stargazers_count":3,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-26T23:04:13.094Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kellpossible.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-03-01T21:59:21.000Z","updated_at":"2020-06-17T18:57:34.000Z","dependencies_parsed_at":"2022-08-27T22:41:14.072Z","dependency_job_id":null,"html_url":"https://github.com/kellpossible/commodity","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kellpossible%2Fcommodity","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kellpossible%2Fcommodity/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kellpossible%2Fcommodity/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kellpossible%2Fcommodity/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kellpossible","download_url":"https://codeload.github.com/kellpossible/commodity/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248447548,"owners_count":21105137,"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":[],"created_at":"2024-10-14T18:47:51.975Z","updated_at":"2025-04-13T06:27:59.783Z","avatar_url":"https://github.com/kellpossible.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Commodity [![crates.io badge](https://img.shields.io/crates/v/commodity.svg)](https://crates.io/crates/commodity) [![docs.rs badge](https://docs.rs/commodity/badge.svg)](https://docs.rs/commodity/) [![license badge](https://img.shields.io/github/license/kellpossible/commodity)](https://github.com/kellpossible/commodity/blob/master/LICENSE.txt) [![github action badge](https://github.com/kellpossible/commodity/workflows/Rust/badge.svg)](https://github.com/kellpossible/commodity/actions?query=workflow%3ARust)\n\nA library for representing commodities/currencies, and exchange rates/conversions between them in Rust. Values are backed by the [rust_decimal](https://crates.io/crates/rust_decimal) library.\n\n**[Changelog](./CHANGELOG.md)**\n\n## Optional Features\n\nThe following features can be enabled to provide extra functionality:\n\n+ `serde-support`\n  + Enables support for serialization/de-serialization via `serde`\n\n## Example\n\n```rust\nuse commodity::{Commodity, CommodityType, CommodityTypeID};\nuse rust_decimal::Decimal;\nuse std::str::FromStr;\n\n// Create a commodity type from a currency's iso4317 three character code.\n// The CommodityType stores information associated with that currency,\n// such as the full name (\"United States dollar\" for this one).\nlet usd = CommodityType::from_currency_alpha3(\"USD\").unwrap();\n\n// Create a commodity with a value of \"2.02 USD\"\nlet commodity1 = Commodity::new(Decimal::from_str(\"2.02\").unwrap(), \u0026usd);\n\n// Create commodities using the `from_str` method\nlet commodity2 = Commodity::from_str(\"24.00 USD\").unwrap();\n\n// Create commodity using a CommodityTypeID\nlet nzd_code = CommodityTypeID::from_str(\"NZD\").unwrap();\nlet commodity3 = Commodity::new(Decimal::from_str(\"24.00\").unwrap(), nzd_code);\n\n// Add two compatible (same currency) commodities, the result has\n// the same currency (in this case, \"USD\").\nlet commodity4 = commodity1.add(\u0026commodity2).unwrap();\n\n// Try to subtract two incompatible commodities\nlet result = commodity3.sub(\u0026commodity2);\nassert!(result.is_err());\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkellpossible%2Fcommodity","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkellpossible%2Fcommodity","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkellpossible%2Fcommodity/lists"}