32 breaking releases

0.33.0 Aug 14, 2024
0.32.0 Jul 24, 2024
0.31.0 Jun 12, 2024
0.29.0 Mar 1, 2024
0.7.0 Nov 9, 2021

#21 in Windows APIs

Download history 18527/week @ 2024-07-18 19059/week @ 2024-07-25 19215/week @ 2024-08-01 21987/week @ 2024-08-08 21394/week @ 2024-08-15 20016/week @ 2024-08-22 22409/week @ 2024-08-29 22230/week @ 2024-09-05 21082/week @ 2024-09-12 18870/week @ 2024-09-19 23282/week @ 2024-09-26 24907/week @ 2024-10-03 24930/week @ 2024-10-10 24905/week @ 2024-10-17 24159/week @ 2024-10-24 27196/week @ 2024-10-31

105,232 downloads per month
Used in 237 crates (14 directly)

MIT license

33MB
45K SLoC

webview2-com

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.

Getting Started

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.

Safety

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.

Convenience Types

Most of the code added by this crate consists of convenience types to implement COM interfaces that are required for callbacks and setting options:

  • callback.rs: Implements all of the event sink handler interfaces used by WebView2.
  • options.rs: Implements the 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:

  • pwstr.rs: string_from_pcwstr, take_pwstr, and pwstr_from_str.

Windows Metadata

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.

Dependencies

~127MB
~2M SLoC