Module cef::rc

source ·
Expand description

Reference counted module

Many cef types are reference counted, this module is the building block to create them. Users typically don’t need to uses these types, but anyone who want to add feaures and implementations to this crate will need to understand them.

In order to create a new Rust type for a raw cef type, simply create a module for it first. And then work on the implementations based on following conditions:

If raw cef type is a simple struct with basic fields

For example like cef_settings_t, just create a struct like Settings and define a method into_raw that can convert to raw cef type.

If raw cef type has cef_base_ref_counted_t

…and it’s a type we should create in Rust and pass to C API

For example like cef_app_t, Define a trait like App with trait bound of Clone, Send,and Sync. We need Clone trait because this will be a reference counted type, and users can decide how to clone the value of the type. We need Send and Sync to make sure it’s thread safe. Each field of this kind of cef type usually is a callback like Option<unsafe extern "C" fn(...)>. We define a trampoline function with the same signature, and then define a trait method like App::on_before_command_line_processing. Finally, define a trait method to_raw that can create raw cef type with reference counted. In the implementation of to_raw, create the raw cef type by unsafe { std::mem::zeroed } first. And then fill each field by adding the trampoline function. Return the value by calling RcImpl::new. This is the wrapper to add cef_base_ref_counted_t to the type, so the trampoline function can call RcImpl::get to retreive rust type and use it.

… and if it’s a type we sould get from C API

For example like cef_command_line_t, it should implement Rc trait fisrt. There are some private macros impl_rc in this module for you to implement it. And then define a new type like CommandLine to wrap the raw type with RefGuard. Finally, define a method called from_raw.

Structs

  • There are some types require users to implement one their own in Rust and then create a raw type around it to pass to sys level api. This is the wrapper type for it.
  • A smart pointer for types from cef library.

Traits

Functions