Skip to main content

Service

Trait Service 

Source
pub trait Service: Send + Sync {
    // Required method
    fn call(&self, method: &str, args: &[Value]) -> Result<Value, ServiceError>;
}
Expand description

Unified interface for cross-plugin calls.

Each plugin registers one or more services that other plugins can call through Service::call().

§Example

use openstranded_common_wasmcontract::{Service, Value, ServiceError};

struct HealthService;

impl Service for HealthService {
    fn call(&self, method: &str, args: &[Value]) -> Result<Value, ServiceError> {
        match method {
            "get_max" => Ok(Value::U32(100)),
            _ => Err(ServiceError::UnknownMethod(method.into())),
        }
    }
}

Required Methods§

Source

fn call(&self, method: &str, args: &[Value]) -> Result<Value, ServiceError>

Call a method on this service.

  • method: method name (case-sensitive string)
  • args: call arguments

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§