Struct SdkClient

Source
pub struct SdkClient { /* private fields */ }

Implementations§

Source§

impl SdkClient

Source

pub fn new(client: MykoClient) -> Self

Source

pub async fn add_instance(&self, args: InstanceArgs) -> InstanceProxy

Examples found in repository?
examples/hello_rship.rs (lines 34-44)
15pub async fn start_client() {
16    // Initialize logger
17    env_logger::init();
18    
19    // Load the environment variables
20    let address = std::env::var("RSHIP_ADDRESS").unwrap_or_else(|_| "dev.rship.io".to_string());
21    let port = std::env::var("RSHIP_PORT").unwrap_or_else(|_| "5155".to_string());
22    let url = format!("ws://{}:{}/myko", address, port);
23    log::info!("Connecting to: {}", url);
24
25    // Create a new sdk client
26    let sdk = SdkClient::init();
27    sdk.set_address(Some(url));
28
29    // Wait for the client to connect
30    sdk.await_connection().await;
31
32    // Create an instance
33    let instance = sdk
34        .add_instance(InstanceArgs {
35            name: "Rust SDK Example".into(),
36            short_id: "rust-sdk-example".into(),
37            code: "rust-sdk-example".into(),
38            service_id: "rust-sdk-service".into(),
39            cluster_id: None,
40            color: "#FF6B35".into(),
41            machine_id: "rust-sdk-machine".into(),
42            message: Some("Hello from Rust SDK!".into()),
43            status: rship_sdk::InstanceStatus::Available,
44        })
45        .await;
46
47    // Create a target
48    let mut target = instance
49        .add_target(TargetArgs {
50            name: "SDK Example Target".into(),
51            short_id: "sdk-example-target".into(),
52            category: "examples".into(),
53            parent_targets: None,
54        })
55        .await;
56
57    // Add an action to the target
58    target
59        .add_action(
60            ActionArgs::<MyActionData>::new("Print Log".into(), "print-log".into()),
61            |action, data| {
62                println!("{}", data.data);
63            },
64        )
65        .await;
66
67    // Add an emitter to the target
68    let emitter = target
69        .add_emitter(EmitterArgs::<MyEmitterType>::new(
70            "Number Go Up".into(),
71            "number-go-up".into(),
72        ))
73        .await;
74
75    // Pulse the emitter
76    let mut counter = 0;
77    loop {
78        emitter.pulse(MyEmitterType { data: format!("{}", counter) }).await.expect("Failed to pulse emitter");
79        counter += 1;
80        tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
81    }
82}
More examples
Hide additional examples
examples/hello_rship_enum.rs (lines 77-87)
58pub async fn start_client() {
59    // Initialize logger
60    env_logger::init();
61
62    // Load the environment variables
63    let address = std::env::var("RSHIP_ADDRESS").unwrap_or_else(|_| "localhost".to_string());
64    let port = std::env::var("RSHIP_PORT").unwrap_or_else(|_| "5155".to_string());
65    let url = format!("ws://{}:{}/myko", address, port);
66    log::info!("Connecting to: {}", url);
67
68    // Create a new sdk client
69    let sdk = SdkClient::init();
70    sdk.set_address(Some(url));
71
72    // Wait for the client to connect
73    sdk.await_connection().await;
74
75    // Create an instance
76    let instance = sdk
77        .add_instance(InstanceArgs {
78            name: "Rust SDK Example".into(),
79            short_id: "rust-sdk-example".into(),
80            code: "rust-sdk-example".into(),
81            service_id: "rust-sdk-service".into(),
82            cluster_id: None,
83            color: "#FF6B35".into(),
84            machine_id: "rust-sdk-machine".into(),
85            message: Some("Hello from Rust SDK!".into()),
86            status: rship_sdk::InstanceStatus::Available,
87        })
88        .await;
89
90    // Create a target
91    let mut target = instance
92        .add_target(TargetArgs {
93            name: "SDK Example Target".into(),
94            short_id: "sdk-example-target".into(),
95            category: "examples".into(),
96            parent_targets: None,
97        })
98        .await;
99
100    // Add an action to the target (struct example)
101    target
102        .add_action(
103            ActionArgs::<MyActionData>::new("Print Log".into(), "print-log".into()),
104            |action, data| {
105                println!("{}", data.data);
106            },
107        )
108        .await;
109
110    target
111        .add_action(
112            ActionArgs::<SetButtonStateAction>::new(
113                "Object With Enums".into(),
114                "object-with-enums".into(),
115            ),
116            |action, data| {
117                println!("Object With Enums: {:?}", data);
118            },
119        )
120        .await;
121
122    println!("{}", json!(schema_for!(SetButtonStateAction)));
123
124    // Add an emitter to the target
125    let emitter = target
126        .add_emitter(EmitterArgs::<MyEmitterType>::new(
127            "Number Go Up".into(),
128            "number-go-up".into(),
129        ))
130        .await;
131
132    // Pulse the emitter
133    let mut counter = 0;
134    loop {
135        emitter
136            .pulse(MyEmitterType {
137                data: format!("{}", counter),
138            })
139            .await
140            .expect("Failed to pulse emitter");
141        counter += 1;
142        tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
143    }
144}
Source

pub async fn pulse_emitter( &self, service_short_id: String, target_short_id: String, emitter_short_id: String, data: impl JsonSchema + Serialize, ) -> Result<(), String>

Source

pub async fn await_connection(&self)

Examples found in repository?
examples/hello_rship.rs (line 30)
15pub async fn start_client() {
16    // Initialize logger
17    env_logger::init();
18    
19    // Load the environment variables
20    let address = std::env::var("RSHIP_ADDRESS").unwrap_or_else(|_| "dev.rship.io".to_string());
21    let port = std::env::var("RSHIP_PORT").unwrap_or_else(|_| "5155".to_string());
22    let url = format!("ws://{}:{}/myko", address, port);
23    log::info!("Connecting to: {}", url);
24
25    // Create a new sdk client
26    let sdk = SdkClient::init();
27    sdk.set_address(Some(url));
28
29    // Wait for the client to connect
30    sdk.await_connection().await;
31
32    // Create an instance
33    let instance = sdk
34        .add_instance(InstanceArgs {
35            name: "Rust SDK Example".into(),
36            short_id: "rust-sdk-example".into(),
37            code: "rust-sdk-example".into(),
38            service_id: "rust-sdk-service".into(),
39            cluster_id: None,
40            color: "#FF6B35".into(),
41            machine_id: "rust-sdk-machine".into(),
42            message: Some("Hello from Rust SDK!".into()),
43            status: rship_sdk::InstanceStatus::Available,
44        })
45        .await;
46
47    // Create a target
48    let mut target = instance
49        .add_target(TargetArgs {
50            name: "SDK Example Target".into(),
51            short_id: "sdk-example-target".into(),
52            category: "examples".into(),
53            parent_targets: None,
54        })
55        .await;
56
57    // Add an action to the target
58    target
59        .add_action(
60            ActionArgs::<MyActionData>::new("Print Log".into(), "print-log".into()),
61            |action, data| {
62                println!("{}", data.data);
63            },
64        )
65        .await;
66
67    // Add an emitter to the target
68    let emitter = target
69        .add_emitter(EmitterArgs::<MyEmitterType>::new(
70            "Number Go Up".into(),
71            "number-go-up".into(),
72        ))
73        .await;
74
75    // Pulse the emitter
76    let mut counter = 0;
77    loop {
78        emitter.pulse(MyEmitterType { data: format!("{}", counter) }).await.expect("Failed to pulse emitter");
79        counter += 1;
80        tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
81    }
82}
More examples
Hide additional examples
examples/hello_rship_enum.rs (line 73)
58pub async fn start_client() {
59    // Initialize logger
60    env_logger::init();
61
62    // Load the environment variables
63    let address = std::env::var("RSHIP_ADDRESS").unwrap_or_else(|_| "localhost".to_string());
64    let port = std::env::var("RSHIP_PORT").unwrap_or_else(|_| "5155".to_string());
65    let url = format!("ws://{}:{}/myko", address, port);
66    log::info!("Connecting to: {}", url);
67
68    // Create a new sdk client
69    let sdk = SdkClient::init();
70    sdk.set_address(Some(url));
71
72    // Wait for the client to connect
73    sdk.await_connection().await;
74
75    // Create an instance
76    let instance = sdk
77        .add_instance(InstanceArgs {
78            name: "Rust SDK Example".into(),
79            short_id: "rust-sdk-example".into(),
80            code: "rust-sdk-example".into(),
81            service_id: "rust-sdk-service".into(),
82            cluster_id: None,
83            color: "#FF6B35".into(),
84            machine_id: "rust-sdk-machine".into(),
85            message: Some("Hello from Rust SDK!".into()),
86            status: rship_sdk::InstanceStatus::Available,
87        })
88        .await;
89
90    // Create a target
91    let mut target = instance
92        .add_target(TargetArgs {
93            name: "SDK Example Target".into(),
94            short_id: "sdk-example-target".into(),
95            category: "examples".into(),
96            parent_targets: None,
97        })
98        .await;
99
100    // Add an action to the target (struct example)
101    target
102        .add_action(
103            ActionArgs::<MyActionData>::new("Print Log".into(), "print-log".into()),
104            |action, data| {
105                println!("{}", data.data);
106            },
107        )
108        .await;
109
110    target
111        .add_action(
112            ActionArgs::<SetButtonStateAction>::new(
113                "Object With Enums".into(),
114                "object-with-enums".into(),
115            ),
116            |action, data| {
117                println!("Object With Enums: {:?}", data);
118            },
119        )
120        .await;
121
122    println!("{}", json!(schema_for!(SetButtonStateAction)));
123
124    // Add an emitter to the target
125    let emitter = target
126        .add_emitter(EmitterArgs::<MyEmitterType>::new(
127            "Number Go Up".into(),
128            "number-go-up".into(),
129        ))
130        .await;
131
132    // Pulse the emitter
133    let mut counter = 0;
134    loop {
135        emitter
136            .pulse(MyEmitterType {
137                data: format!("{}", counter),
138            })
139            .await
140            .expect("Failed to pulse emitter");
141        counter += 1;
142        tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
143    }
144}
Source

pub fn init() -> Self

Examples found in repository?
examples/hello_rship.rs (line 26)
15pub async fn start_client() {
16    // Initialize logger
17    env_logger::init();
18    
19    // Load the environment variables
20    let address = std::env::var("RSHIP_ADDRESS").unwrap_or_else(|_| "dev.rship.io".to_string());
21    let port = std::env::var("RSHIP_PORT").unwrap_or_else(|_| "5155".to_string());
22    let url = format!("ws://{}:{}/myko", address, port);
23    log::info!("Connecting to: {}", url);
24
25    // Create a new sdk client
26    let sdk = SdkClient::init();
27    sdk.set_address(Some(url));
28
29    // Wait for the client to connect
30    sdk.await_connection().await;
31
32    // Create an instance
33    let instance = sdk
34        .add_instance(InstanceArgs {
35            name: "Rust SDK Example".into(),
36            short_id: "rust-sdk-example".into(),
37            code: "rust-sdk-example".into(),
38            service_id: "rust-sdk-service".into(),
39            cluster_id: None,
40            color: "#FF6B35".into(),
41            machine_id: "rust-sdk-machine".into(),
42            message: Some("Hello from Rust SDK!".into()),
43            status: rship_sdk::InstanceStatus::Available,
44        })
45        .await;
46
47    // Create a target
48    let mut target = instance
49        .add_target(TargetArgs {
50            name: "SDK Example Target".into(),
51            short_id: "sdk-example-target".into(),
52            category: "examples".into(),
53            parent_targets: None,
54        })
55        .await;
56
57    // Add an action to the target
58    target
59        .add_action(
60            ActionArgs::<MyActionData>::new("Print Log".into(), "print-log".into()),
61            |action, data| {
62                println!("{}", data.data);
63            },
64        )
65        .await;
66
67    // Add an emitter to the target
68    let emitter = target
69        .add_emitter(EmitterArgs::<MyEmitterType>::new(
70            "Number Go Up".into(),
71            "number-go-up".into(),
72        ))
73        .await;
74
75    // Pulse the emitter
76    let mut counter = 0;
77    loop {
78        emitter.pulse(MyEmitterType { data: format!("{}", counter) }).await.expect("Failed to pulse emitter");
79        counter += 1;
80        tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
81    }
82}
More examples
Hide additional examples
examples/hello_rship_enum.rs (line 69)
58pub async fn start_client() {
59    // Initialize logger
60    env_logger::init();
61
62    // Load the environment variables
63    let address = std::env::var("RSHIP_ADDRESS").unwrap_or_else(|_| "localhost".to_string());
64    let port = std::env::var("RSHIP_PORT").unwrap_or_else(|_| "5155".to_string());
65    let url = format!("ws://{}:{}/myko", address, port);
66    log::info!("Connecting to: {}", url);
67
68    // Create a new sdk client
69    let sdk = SdkClient::init();
70    sdk.set_address(Some(url));
71
72    // Wait for the client to connect
73    sdk.await_connection().await;
74
75    // Create an instance
76    let instance = sdk
77        .add_instance(InstanceArgs {
78            name: "Rust SDK Example".into(),
79            short_id: "rust-sdk-example".into(),
80            code: "rust-sdk-example".into(),
81            service_id: "rust-sdk-service".into(),
82            cluster_id: None,
83            color: "#FF6B35".into(),
84            machine_id: "rust-sdk-machine".into(),
85            message: Some("Hello from Rust SDK!".into()),
86            status: rship_sdk::InstanceStatus::Available,
87        })
88        .await;
89
90    // Create a target
91    let mut target = instance
92        .add_target(TargetArgs {
93            name: "SDK Example Target".into(),
94            short_id: "sdk-example-target".into(),
95            category: "examples".into(),
96            parent_targets: None,
97        })
98        .await;
99
100    // Add an action to the target (struct example)
101    target
102        .add_action(
103            ActionArgs::<MyActionData>::new("Print Log".into(), "print-log".into()),
104            |action, data| {
105                println!("{}", data.data);
106            },
107        )
108        .await;
109
110    target
111        .add_action(
112            ActionArgs::<SetButtonStateAction>::new(
113                "Object With Enums".into(),
114                "object-with-enums".into(),
115            ),
116            |action, data| {
117                println!("Object With Enums: {:?}", data);
118            },
119        )
120        .await;
121
122    println!("{}", json!(schema_for!(SetButtonStateAction)));
123
124    // Add an emitter to the target
125    let emitter = target
126        .add_emitter(EmitterArgs::<MyEmitterType>::new(
127            "Number Go Up".into(),
128            "number-go-up".into(),
129        ))
130        .await;
131
132    // Pulse the emitter
133    let mut counter = 0;
134    loop {
135        emitter
136            .pulse(MyEmitterType {
137                data: format!("{}", counter),
138            })
139            .await
140            .expect("Failed to pulse emitter");
141        counter += 1;
142        tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
143    }
144}
Source

pub fn set_address(&self, address: Option<String>)

Examples found in repository?
examples/hello_rship.rs (line 27)
15pub async fn start_client() {
16    // Initialize logger
17    env_logger::init();
18    
19    // Load the environment variables
20    let address = std::env::var("RSHIP_ADDRESS").unwrap_or_else(|_| "dev.rship.io".to_string());
21    let port = std::env::var("RSHIP_PORT").unwrap_or_else(|_| "5155".to_string());
22    let url = format!("ws://{}:{}/myko", address, port);
23    log::info!("Connecting to: {}", url);
24
25    // Create a new sdk client
26    let sdk = SdkClient::init();
27    sdk.set_address(Some(url));
28
29    // Wait for the client to connect
30    sdk.await_connection().await;
31
32    // Create an instance
33    let instance = sdk
34        .add_instance(InstanceArgs {
35            name: "Rust SDK Example".into(),
36            short_id: "rust-sdk-example".into(),
37            code: "rust-sdk-example".into(),
38            service_id: "rust-sdk-service".into(),
39            cluster_id: None,
40            color: "#FF6B35".into(),
41            machine_id: "rust-sdk-machine".into(),
42            message: Some("Hello from Rust SDK!".into()),
43            status: rship_sdk::InstanceStatus::Available,
44        })
45        .await;
46
47    // Create a target
48    let mut target = instance
49        .add_target(TargetArgs {
50            name: "SDK Example Target".into(),
51            short_id: "sdk-example-target".into(),
52            category: "examples".into(),
53            parent_targets: None,
54        })
55        .await;
56
57    // Add an action to the target
58    target
59        .add_action(
60            ActionArgs::<MyActionData>::new("Print Log".into(), "print-log".into()),
61            |action, data| {
62                println!("{}", data.data);
63            },
64        )
65        .await;
66
67    // Add an emitter to the target
68    let emitter = target
69        .add_emitter(EmitterArgs::<MyEmitterType>::new(
70            "Number Go Up".into(),
71            "number-go-up".into(),
72        ))
73        .await;
74
75    // Pulse the emitter
76    let mut counter = 0;
77    loop {
78        emitter.pulse(MyEmitterType { data: format!("{}", counter) }).await.expect("Failed to pulse emitter");
79        counter += 1;
80        tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
81    }
82}
More examples
Hide additional examples
examples/hello_rship_enum.rs (line 70)
58pub async fn start_client() {
59    // Initialize logger
60    env_logger::init();
61
62    // Load the environment variables
63    let address = std::env::var("RSHIP_ADDRESS").unwrap_or_else(|_| "localhost".to_string());
64    let port = std::env::var("RSHIP_PORT").unwrap_or_else(|_| "5155".to_string());
65    let url = format!("ws://{}:{}/myko", address, port);
66    log::info!("Connecting to: {}", url);
67
68    // Create a new sdk client
69    let sdk = SdkClient::init();
70    sdk.set_address(Some(url));
71
72    // Wait for the client to connect
73    sdk.await_connection().await;
74
75    // Create an instance
76    let instance = sdk
77        .add_instance(InstanceArgs {
78            name: "Rust SDK Example".into(),
79            short_id: "rust-sdk-example".into(),
80            code: "rust-sdk-example".into(),
81            service_id: "rust-sdk-service".into(),
82            cluster_id: None,
83            color: "#FF6B35".into(),
84            machine_id: "rust-sdk-machine".into(),
85            message: Some("Hello from Rust SDK!".into()),
86            status: rship_sdk::InstanceStatus::Available,
87        })
88        .await;
89
90    // Create a target
91    let mut target = instance
92        .add_target(TargetArgs {
93            name: "SDK Example Target".into(),
94            short_id: "sdk-example-target".into(),
95            category: "examples".into(),
96            parent_targets: None,
97        })
98        .await;
99
100    // Add an action to the target (struct example)
101    target
102        .add_action(
103            ActionArgs::<MyActionData>::new("Print Log".into(), "print-log".into()),
104            |action, data| {
105                println!("{}", data.data);
106            },
107        )
108        .await;
109
110    target
111        .add_action(
112            ActionArgs::<SetButtonStateAction>::new(
113                "Object With Enums".into(),
114                "object-with-enums".into(),
115            ),
116            |action, data| {
117                println!("Object With Enums: {:?}", data);
118            },
119        )
120        .await;
121
122    println!("{}", json!(schema_for!(SetButtonStateAction)));
123
124    // Add an emitter to the target
125    let emitter = target
126        .add_emitter(EmitterArgs::<MyEmitterType>::new(
127            "Number Go Up".into(),
128            "number-go-up".into(),
129        ))
130        .await;
131
132    // Pulse the emitter
133    let mut counter = 0;
134    loop {
135        emitter
136            .pulse(MyEmitterType {
137                data: format!("{}", counter),
138            })
139            .await
140            .expect("Failed to pulse emitter");
141        counter += 1;
142        tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
143    }
144}

Trait Implementations§

Source§

impl Clone for SdkClient

Source§

fn clone(&self) -> SdkClient

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> ErasedDestructor for T
where T: 'static,