Skip to main content

Source

Trait Source 

Source
pub trait Source: Send + Sync {
    // Required methods
    fn claim(
        &self,
        name: &str,
    ) -> Pin<Box<dyn Future<Output = Option<PvInfo>> + Send + '_>>;
    fn get(
        &self,
        name: &str,
    ) -> Pin<Box<dyn Future<Output = Option<NtPayload>> + Send + '_>>;
    fn put(
        &self,
        name: &str,
        value: &DecodedValue,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<(String, NtPayload)>, String>> + Send + '_>>;
    fn subscribe(
        &self,
        name: &str,
    ) -> Pin<Box<dyn Future<Output = Option<Receiver<NtPayload>>> + Send + '_>>;
    fn names(&self) -> Pin<Box<dyn Future<Output = Vec<String>> + Send + '_>>;

    // Provided method
    fn rpc(
        &self,
        _name: &str,
        _args: &DecodedValue,
    ) -> Pin<Box<dyn Future<Output = Result<NtPayload, String>> + Send + '_>> { ... }
}
Expand description

Object-safe trait for a PV data provider.

A source is responsible for a set of PV names. The server’s SourceRegistry iterates sources in priority order to find the first that claims a given name.

§Implementing a custom source

use spvirit_server::pvstore::{Source, PvInfo};

struct MySource { /* ... */ }

impl Source for MySource {
    fn claim(&self, name: &str) -> Pin<Box<dyn Future<Output = Option<PvInfo>> + Send + '_>> {
        Box::pin(async move { /* ... */ })
    }
    // ...other methods...
}

Required Methods§

Source

fn claim( &self, name: &str, ) -> Pin<Box<dyn Future<Output = Option<PvInfo>> + Send + '_>>

Check whether this source owns name and, if so, return its metadata.

Return None to let the registry try the next source.

Source

fn get( &self, name: &str, ) -> Pin<Box<dyn Future<Output = Option<NtPayload>> + Send + '_>>

Read the current value of a PV.

Only called for PVs this source has previously claimed.

Source

fn put( &self, name: &str, value: &DecodedValue, ) -> Pin<Box<dyn Future<Output = Result<Vec<(String, NtPayload)>, String>> + Send + '_>>

Apply a PUT value to a PV.

Returns the list of (pv_name, updated_payload) pairs for all PVs that changed as a result (e.g. forward-link propagation).

Source

fn subscribe( &self, name: &str, ) -> Pin<Box<dyn Future<Output = Option<Receiver<NtPayload>>> + Send + '_>>

Subscribe to value-change notifications on a PV.

Returns None if the PV does not support subscription.

Source

fn names(&self) -> Pin<Box<dyn Future<Output = Vec<String>> + Send + '_>>

List all PV names provided by this source.

Provided Methods§

Source

fn rpc( &self, _name: &str, _args: &DecodedValue, ) -> Pin<Box<dyn Future<Output = Result<NtPayload, String>> + Send + '_>>

Execute an RPC call on a channel.

name is the channel name, args is the decoded request structure. Returns the response payload on success.

The default implementation returns an error — override it in sources that provide RPC endpoints.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§