{"id":22696102,"url":"https://github.com/zdimension/variant-rs","last_synced_at":"2025-07-25T05:09:49.810Z","repository":{"id":57711072,"uuid":"467989556","full_name":"zdimension/variant-rs","owner":"zdimension","description":null,"archived":false,"fork":false,"pushed_at":"2024-02-02T21:56:26.000Z","size":57,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-10T12:53:44.302Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/zdimension.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2022-03-09T15:43:21.000Z","updated_at":"2023-12-21T06:42:22.000Z","dependencies_parsed_at":"2023-02-09T17:16:09.309Z","dependency_job_id":null,"html_url":"https://github.com/zdimension/variant-rs","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zdimension%2Fvariant-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zdimension%2Fvariant-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zdimension%2Fvariant-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zdimension%2Fvariant-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zdimension","download_url":"https://codeload.github.com/zdimension/variant-rs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248658753,"owners_count":21140997,"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-12-10T04:14:14.346Z","updated_at":"2025-04-13T03:26:29.786Z","avatar_url":"https://github.com/zdimension.png","language":"Rust","readme":"# variant-rs\r\n\r\n[![Crates.io](https://img.shields.io/crates/v/variant-rs)](https://crates.io/crates/variant-rs)\r\n[![Crates.io](https://img.shields.io/crates/d/variant-rs)](https://crates.io/crates/variant-rs)\r\n[![License](https://img.shields.io/badge/license-Apache%202.0-blue)](https://github.com/zdimension/variant-rs/blob/master/LICENSE-APACHE)\r\n[![License](https://img.shields.io/badge/license-MIT-blue)](https://github.com/zdimension/variant-rs/blob/master/LICENSE-MIT)\r\n\r\n`variant-rs` is a Rust crate that provides idiomatic handling of COM `VARIANT` types. Rust supports discriminated\r\nunion types out of the box, so although `VARIANT`s are usually a pain to work with, Rust makes it easy to encode and\r\ndecode them.\r\n\r\nThe crate is designed to work with the `VARIANT` type from the [`winapi`](https://crates.io/crates/winapi) crate.\r\n\r\n## Basic usage\r\n```rust\r\nuse variant_rs::*;\r\n\r\nfn main() {\r\n    let v1 = Variant::I32(123); // manual instanciation\r\n    let v2 = 123i32.to_variant(); // ToVariant trait\r\n    let v3 = 123.into(); // From / Into traits\r\n    assert_eq!(v1, v2);\r\n    assert_eq!(v1, v3);\r\n  \r\n    let bstr: Variant = \"Hello, world!\".into();\r\n    let ptr: VARIANT = bstr.clone().try_into().unwrap(); // convert to COM VARIANT\r\n    let back: Variant = ptr.try_into().unwrap(); // convert back\r\n    assert_eq!(bstr, back);\r\n}\r\n```\r\n\r\n## Supported `VARIANT` types and corresponding types\r\n| `VARIANT` type | Rust type           | Rust type (BY_REF)             |\r\n|----------------|---------------------|--------------------------------|\r\n| `VT_EMPTY`     | `()`                | N/A                            |\r\n| `VT_NULL`      | `()`                | N/A                            |\r\n| `VT_I1`        | `i8`                | `PSTR`                         |\r\n| `VT_I2`        | `i16`               | `\u0026'static mut i16`             |\r\n| `VT_I4`        | `i32`               | `\u0026'static mut i32`             |\r\n| `VT_I8`        | `i64`               | `\u0026'static mut i64`             |\r\n| `VT_UI1`       | `u8`                | `\u0026'static mut u8`              |\r\n| `VT_UI2`       | `u16`               | `\u0026'static mut u16`             |\r\n| `VT_UI4`       | `u32`               | `\u0026'static mut u32`             |\r\n| `VT_UI8`       | `u64`               | `\u0026'static mut u64`             |\r\n| `VT_INT`       | `i32`               | `\u0026'static mut i32`             |\r\n| `VT_UINT`      | `u32`               | `\u0026'static mut u32`             |\r\n| `VT_R4`        | `f32`               | `\u0026'static mut f32`             |\r\n| `VT_R8`        | `f64`               | `\u0026'static mut f64`             |\r\n| `VT_BOOL`      | `bool`              | `\u0026'static mut ComBool`         |\r\n| `VT_BSTR`      | `BSTR`              | `\u0026'static mut BSTR`            |\r\n| `VT_ERROR`     | `HRESULT` (`i32`)   | `\u0026'static mut HRESULT` (`i32`) |\r\n| `VT_CY`        | `Currency`          | `\u0026'static mut ComCurrency`     |\r\n| `VT_DATE`      | `NaiveDateTime`     | `\u0026'static mut ComDate`         |\r\n| `VT_DECIMAL`   | `Decimal`           | `\u0026'static mut ComDecimal`      |\r\n| `VT_UNKNOWN`   | `Option\u003cIUnknown\u003e`  | N/A                            |\r\n| `VT_DISPATCH`  | `Option\u003cIDispatch\u003e` | N/A                            |\r\n| `VT_VARIANT`   | N/A                 | `PtrWrapper\u003cVARIANT\u003e`          |\r\n\r\n## Wrapper types\r\n\r\n### `ComBool`\r\n`i16`-backed enum.\r\n\r\n### `ComCurrency`\r\nMaps COM's `i64` currency data [`CY`](https://docs.microsoft.com/en-us/windows/win32/api/wtypes/ns-wtypes-cy-r1) to [`Decimal`](https://docs.rs/rust_decimal/latest/rust_decimal/struct.Decimal.html).\r\n\r\n### `ComDecimal`\r\nMaps COM's 96-bit decimals [`DECIMAL`](https://docs.microsoft.com/en-us/windows/win32/api/wtypes/ns-wtypes-decimal-r1) to [`Decimal`](https://docs.rs/rust_decimal/latest/rust_decimal/struct.Decimal.html).\r\n\r\n### `ComData`\r\nMaps COM's [`DATE`](https://docs.microsoft.com/en-us/cpp/atl-mfc-shared/date-type?view=msvc-170) (`f64` milliseconds from 1899-12-30) to [`NaiveDateTime`](https://docs.rs/chrono/latest/chrono/naive/struct.NaiveDateTime.html).\r\n\r\n### `PtrWrapper`\r\nSafe wrapper around COM interface pointers.\r\n\r\n## Installation\r\nAdd this to your `Cargo.toml`:\r\n```toml\r\n[dependencies]\r\nvariant-rs = \"0.4.0\"\r\n```\r\n\r\n## License\r\nThis project is licensed under either of\r\n* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or\r\n  \u003chttps://www.apache.org/licenses/LICENSE-2.0\u003e)\r\n* MIT license ([LICENSE-MIT](LICENSE-MIT) or\r\n  \u003chttps://opensource.org/licenses/MIT\u003e)\r\n  at your option.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzdimension%2Fvariant-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzdimension%2Fvariant-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzdimension%2Fvariant-rs/lists"}