variant-rs
variant-rs
is a Rust crate that provides idiomatic handling of COM VARIANT
types. Rust supports discriminated
union types out of the box, so although VARIANT
s are usually a pain to work with, Rust makes it easy to encode and
decode them.
The crate is designed to work with the VARIANT
type from the winapi
crate.
Basic usage
use *;
Supported VARIANT
types and corresponding types
VARIANT type |
Rust type | Rust type (BY_REF) |
---|---|---|
VT_EMPTY |
() |
N/A |
VT_NULL |
() |
N/A |
VT_I1 |
i8 |
PSTR |
VT_I2 |
i16 |
&'static mut i16 |
VT_I4 |
i32 |
&'static mut i32 |
VT_I8 |
i64 |
&'static mut i64 |
VT_UI1 |
u8 |
&'static mut u8 |
VT_UI2 |
u16 |
&'static mut u16 |
VT_UI4 |
u32 |
&'static mut u32 |
VT_UI8 |
u64 |
&'static mut u64 |
VT_INT |
i32 |
&'static mut i32 |
VT_UINT |
u32 |
&'static mut u32 |
VT_R4 |
f32 |
&'static mut f32 |
VT_R8 |
f64 |
&'static mut f64 |
VT_BOOL |
bool |
&'static mut ComBool |
VT_BSTR |
BSTR |
&'static mut BSTR |
VT_ERROR |
HRESULT (i32 ) |
&'static mut HRESULT (i32 ) |
VT_CY |
Currency |
&'static mut ComCurrency |
VT_DATE |
NaiveDateTime |
&'static mut ComDate |
VT_DECIMAL |
Decimal |
&'static mut ComDecimal |
VT_UNKNOWN |
Option<IUnknown> |
N/A |
VT_DISPATCH |
Option<IDispatch> |
N/A |
VT_VARIANT |
N/A | PtrWrapper<VARIANT> |
Wrapper types
ComBool
i16
-backed enum.
ComCurrency
Maps COM's i64
currency data CY
to Decimal
.
ComDecimal
Maps COM's 96-bit decimals DECIMAL
to Decimal
.
ComData
Maps COM's DATE
(f64
milliseconds from 1899-12-30) to NaiveDateTime
.
PtrWrapper
Safe wrapper around COM interface pointers.
Installation
Add this to your Cargo.toml
:
[]
= "0.4.0"
License
This project is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT) at your option.