pub struct EmitterProxy<T: JsonSchema + Serialize + Clone> { /* private fields */ }
Implementations§
Source§impl<T: JsonSchema + Serialize + Clone> EmitterProxy<T>
impl<T: JsonSchema + Serialize + Clone> EmitterProxy<T>
pub async fn save(&self)
pub fn id(&self) -> String
Sourcepub async fn pulse(&self, data: T) -> Result<(), String>
pub async fn pulse(&self, data: T) -> Result<(), String>
Examples found in repository?
examples/hello_rship.rs (line 78)
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
examples/hello_rship_enum.rs (lines 136-138)
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}
Auto Trait Implementations§
impl<T> Freeze for EmitterProxy<T>
impl<T> !RefUnwindSafe for EmitterProxy<T>
impl<T> Send for EmitterProxy<T>where
T: Send,
impl<T> Sync for EmitterProxy<T>where
T: Sync,
impl<T> Unpin for EmitterProxy<T>where
T: Unpin,
impl<T> !UnwindSafe for EmitterProxy<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more