Crates.io | webview2-com |
lib.rs | webview2-com |
version | 0.33.0 |
source | src |
created_at | 2021-09-06 06:08:59.241111 |
updated_at | 2024-08-14 18:30:16.609728 |
description | Rust bindings for the WebView2 COM APIs |
homepage | |
repository | https://github.com/wravery/webview2-rs |
max_upload_size | |
id | 447404 |
size | 103,249 |
This crate implements Rust bindings for the WebView2 COM APIs, as well as several important Win32 APIs necessary to build a standalone GUI application hosting WebView2. The bindings are generated by the Windows crate in webview2-com-sys.
Include a reference to webview2-com
in your Cargo.toml
:
[dependencies]
webview2-com = "0.33"
See the docs or take a look at the sample.rs example (adapted from microsoft/windows-samples-rs) for more details.
Most of the bindings are re-exported transparently from webview2-com-sys
, and they are still marked unsafe
. Unlike typical idiomatic Rust crates wrapped around a -sys
crate, the emphasis of this crate is on writing as little manual wrapper code as possible. This way, webview2-com
can project 100% of the WebView2 COM API, but the downside is you will need to wrap most uses in an unsafe
block or function.
Most of the code added by this crate consists of convenience types to implement COM interfaces that are required for callbacks and setting options:
ICoreWebView2EnvironmentOptions...
interfaces which are passed to CreateCoreWebView2EnvironmentWithOptions
if you want to customize the environment. The CoreWebView2EnvironmentOptions
struct has public accessors for all supported fields with Rust types, so you do not need to use the separate ICoreWebView2EnvironmentOptions...
COM interfaces to initialize or retrieve them.There are also some utilities for dealing with PWSTR
in/out-params that may be useful:
string_from_pcwstr
, take_pwstr
, and pwstr_from_str
.The Windows crate requires a Windows Metadata (winmd
) file describing the API. The one used in this crate was generated with the webview2-win32md project. This crate needs it to use the #[implement]
macro from the Windows crate.