20 releases

Uses new Rust 2024

3.0.0-canary.688 Aug 28, 2025
3.0.0-canary.663 Aug 19, 2025
0.1.20 Jul 24, 2025
0.1.16 Jun 27, 2025
0.1.6 Dec 5, 2024

#716 in Parser implementations

Download history 13/week @ 2025-08-09 97/week @ 2025-08-16 183/week @ 2025-08-23 75/week @ 2025-08-30 4/week @ 2025-09-06 1/week @ 2025-09-13 1/week @ 2025-09-20 22/week @ 2025-09-27 9/week @ 2025-10-04 3/week @ 2025-10-11 7/week @ 2025-10-18 2/week @ 2025-10-25

1,324 downloads per month
Used in 3 crates

AGPL-3.0-or-later

29KB
613 lines

Rship SDK

It is important to know that using a /// comment with 3 slashes inside a struct or enum that is used as Action or Emitter schema will cause the schema to become incompatable with rship (as of 7/25, 3.0.0-canary.616)

please see the examples for usage


lib.rs:

Example Executor

use rship_sdk::{ActionArgs, EmitterArgs, InstanceArgs, SdkClient, TargetArgs};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct MyActionData {
    pub data: String,
}

#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct MyEmitterType {
    pub data: String,
}

pub async fn start_client() {
    // Initialize logger
    env_logger::init();
    
    // Load the environment variables
    let address = std::env::var("RSHIP_ADDRESS").unwrap_or_else(|_| "dev.rship.io".to_string());
    let port = std::env::var("RSHIP_PORT").unwrap_or_else(|_| "5155".to_string());
    let url = format!("ws://{}:{}/myko", address, port);
    log::info!("Connecting to: {}", url);

    // Create a new sdk client
    let sdk = SdkClient::init();
    sdk.set_address(Some(url));

    // Wait for the client to connect
    sdk.await_connection().await;

    // Create an instance
    let instance = sdk
        .add_instance(InstanceArgs {
            name: "Rust SDK Example".into(),
            short_id: "rust-sdk-example".into(),
            code: "rust-sdk-example".into(),
            service_id: "rust-sdk-service".into(),
            cluster_id: None,
            color: "#FF6B35".into(),
            machine_id: "rust-sdk-machine".into(),
            message: Some("Hello from Rust SDK!".into()),
            status: rship_sdk::InstanceStatus::Available,
        })
        .await;

    // Create a target
    let mut target = instance
        .add_target(TargetArgs {
            name: "SDK Example Target".into(),
            short_id: "sdk-example-target".into(),
            category: "examples".into(),
            parent_targets: None,
        })
        .await;

    // Add an action to the target
    target
        .add_action(
            ActionArgs::<MyActionData>::new("Print Log".into(), "print-log".into()),
            |action, data| {
                println!("{}", data.data);
            },
        )
        .await;

    // Add an emitter to the target
    let emitter = target
        .add_emitter(EmitterArgs::<MyEmitterType>::new(
            "Example Emitter".into(),
            "example-emitter".into(),
        ))
        .await;

    // Pulse the emitter
    let mut counter = 0;
    loop {
        emitter.pulse(MyEmitterType { data: format!("{}", counter) }).await.expect("Failed to pulse emitter");
        counter += 1;
        tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
    }
}

#[tokio::main]
async fn main() {
    start_client().await;
}

Dependencies

~12–23MB
~443K SLoC