ServerBinding

Struct ServerBinding 

Source
pub struct ServerBinding { /* private fields */ }
Expand description

Manages the lifecycle of an RPC server.

This struct handles the low-level details of registering an RPC interface with the Windows RPC runtime and managing the listen/stop lifecycle.

§Note

You typically don’t create ServerBinding directly. Instead, use the generated {Interface}Server struct which manages this for you.

§Example

use windows_rpc::rpc_interface;

#[rpc_interface(guid(0x12345678_1234_1234_1234_123456789abc), version(1.0))]
trait MyInterface {
    fn hello() -> i32;
}

struct MyImpl;
impl MyInterfaceServerImpl for MyImpl {
    fn hello() -> i32 { 42 }
}

let mut server = MyInterfaceServer::<MyImpl>::new();
server.register("my_endpoint")?;
server.listen_async()?;
// ... server is now accepting calls ...
server.stop()?;

Implementations§

Source§

impl ServerBinding

Source

pub fn new( protocol: ProtocolSequence, endpoint: impl Into<String>, interface_handle: *const c_void, ) -> Result<Self, Error>

Creates a new server binding for the specified endpoint.

This registers the protocol sequence and endpoint with the RPC runtime, but does not yet register the interface. Call register() to complete the registration.

§Arguments
  • protocol - The protocol sequence to use
  • endpoint - The endpoint name clients will connect to
  • interface_handle - Pointer to the RPC interface specification
§Errors

Returns an error if the protocol sequence and endpoint cannot be registered.

Source

pub fn register(&mut self) -> Result<(), Error>

Registers the RPC interface with the runtime.

After registration, the server can begin accepting calls. This method is idempotent - calling it multiple times has no effect.

§Errors

Returns an error if the interface cannot be registered.

Source

pub fn listen(&self) -> Result<(), Error>

Starts listening for RPC calls (blocking).

This method blocks the current thread until stop() is called from another thread. Use listen_async() for non-blocking operation.

§Errors

Returns an error if:

  • The interface has not been registered
  • The RPC runtime fails to start listening
Source

pub fn listen_async(&self) -> Result<(), Error>

Starts listening for RPC calls (non-blocking).

Returns immediately while RPC calls are processed in background threads managed by the Windows RPC runtime. Call stop() to shut down the server.

This is the recommended mode for most applications as it allows the main thread to continue other work or wait for a shutdown signal.

§Errors

Returns an error if:

  • The interface has not been registered
  • The RPC runtime fails to start listening
Source

pub fn stop(&self) -> Result<(), Error>

Stops the server from accepting new RPC calls.

Outstanding calls may still complete. For a blocking server, this will cause listen() to return.

§Errors

Returns an error if the RPC runtime fails to stop.

Source

pub fn unregister(&mut self) -> Result<(), Error>

Unregisters the RPC interface.

This is called automatically when the ServerBinding is dropped.

§Errors

Returns an error if the interface cannot be unregistered.

Source

pub fn endpoint(&self) -> &str

Returns the endpoint name.

Source

pub fn protocol(&self) -> ProtocolSequence

Returns the protocol sequence.

Trait Implementations§

Source§

impl Drop for ServerBinding

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.