Skip to main content

Dispatch

Trait Dispatch 

Source
pub trait Dispatch: Debug {
    // Required methods
    fn get(&self, dispid: i32) -> Result<Value, ComError>;
    fn put(&self, dispid: i32, value: Value) -> Result<(), ComError>;
    fn call(&self, dispid: i32, args: &[Value]) -> Result<Value, ComError>;

    // Provided methods
    fn duplicate(&self) -> Option<Box<dyn Dispatch>> { ... }
    fn as_idispatch(&self) -> Option<&IDispatch> { ... }
}
Expand description

The late-bound call surface a wrapper needs from a COM object.

Kept deliberately small; it grows a member only when a wrapper first needs one, each with its own test.

Required Methods§

Source

fn get(&self, dispid: i32) -> Result<Value, ComError>

Reads a property by dispatch id (DISPATCH_PROPERTYGET, no arguments).

§Errors

ComError::Hresult if the COM call fails, or ComError::UnexpectedType if the returned value has an unmodeled type.

Source

fn put(&self, dispid: i32, value: Value) -> Result<(), ComError>

Sets a property by dispatch id (DISPATCH_PROPERTYPUT).

Required, deliberately: a default body returning “not implemented” would be a stub that silently turns a missing implementation into a runtime error. Making it required turns that into a compile error instead.

§Errors

ComError::Hresult if the COM call fails.

Source

fn call(&self, dispid: i32, args: &[Value]) -> Result<Value, ComError>

Invokes a method by dispatch id (DISPATCH_METHOD) with arguments.

Required for the same reason as Dispatch::put.

§Errors

ComError::Hresult if the COM call fails, or ComError::UnexpectedType if the returned value has an unmodeled type.

Provided Methods§

Source

fn duplicate(&self) -> Option<Box<dyn Dispatch>>

An owned handle to the same COM object, when there is one.

COM interface pointers are reference counted, so duplicating one is a refcount bump rather than a copy of the object. This exists because passing an object back to the engine needs an owned handle, and a caller normally only has a borrow.

Returns None for test fakes, which have no COM identity to share.

Source

fn as_idispatch(&self) -> Option<&IDispatch>

The underlying IDispatch, when this really is a live COM object.

Returns None for test fakes, which is what stops a fake from being marshalled into a VARIANT and handed to the engine.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§