Enum tether_agent::PlugDefinition
source · pub enum PlugDefinition {
InputPlugDefinition(InputPlugDefinition),
OutputPlugDefinition(OutputPlugDefinition),
}Variants§
InputPlugDefinition(InputPlugDefinition)
OutputPlugDefinition(OutputPlugDefinition)
Implementations§
source§impl PlugDefinition
impl PlugDefinition
pub fn common(&self) -> &PlugDefinitionCommon
sourcepub fn name(&self) -> &str
pub fn name(&self) -> &str
Examples found in repository?
examples/subscribe.rs (line 31)
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
fn main() {
println!("Rust Tether Agent subscribe example");
let mut builder = Builder::from_env(Env::default().default_filter_or("debug"));
builder.init();
debug!("Debugging is enabled; could be verbose");
let tether_agent = TetherAgentOptionsBuilder::new("RustDemoAgent")
.id("example")
.build()
.expect("failed to init Tether agent");
let input_one = PlugOptionsBuilder::create_input("one").build(&tether_agent);
debug!("input one {} = {}", input_one.name(), input_one.topic());
let input_two = PlugOptionsBuilder::create_input("two").build(&tether_agent);
debug!("input two {} = {}", input_two.name(), input_two.topic());
let input_empty = PlugOptionsBuilder::create_input("nothing").build(&tether_agent);
info!("Checking messages every 1s, 10x...");
for i in 1..10 {
info!("#{i}: Checking for messages...");
while let Some((plug_name, message)) = tether_agent.check_messages() {
debug!(
"Received a message topic {} => plug name {}",
message.topic(),
plug_name
);
if &plug_name == input_one.name() {
info!(
"******** INPUT ONE:\n Received a message from plug named \"{}\" on topic {} with length {} bytes",
input_one.name(),
message.topic(),
message.payload().len()
);
}
if &plug_name == input_two.name() {
info!(
"******** INPUT TWO:\n Received a message from plug named \"{}\" on topic {} with length {} bytes",
input_two.name(),
message.topic(),
message.payload().len()
);
// Notice how you must give the from_slice function a type so it knows what to expect
let decoded = from_slice::<CustomMessage>(&message.payload());
match decoded {
Ok(d) => {
info!("Yes, we decoded the MessagePack payload as: {:?}", d);
let CustomMessage { name, id } = d;
debug!("Name is {} and ID is {}", name, id);
}
Err(e) => {
warn!("Failed to decode the payload: {}", e)
}
};
}
if &plug_name == input_empty.name() {
info!(
"******** EMPTY MESSAGE:\n Received a message from plug named \"{}\" on topic {} with length {} bytes",
input_empty.name(),
message.topic(),
message.payload().len()
);
}
}
thread::sleep(Duration::from_millis(1000))
}
}sourcepub fn topic(&self) -> &str
pub fn topic(&self) -> &str
Examples found in repository?
examples/subscribe.rs (line 31)
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
fn main() {
println!("Rust Tether Agent subscribe example");
let mut builder = Builder::from_env(Env::default().default_filter_or("debug"));
builder.init();
debug!("Debugging is enabled; could be verbose");
let tether_agent = TetherAgentOptionsBuilder::new("RustDemoAgent")
.id("example")
.build()
.expect("failed to init Tether agent");
let input_one = PlugOptionsBuilder::create_input("one").build(&tether_agent);
debug!("input one {} = {}", input_one.name(), input_one.topic());
let input_two = PlugOptionsBuilder::create_input("two").build(&tether_agent);
debug!("input two {} = {}", input_two.name(), input_two.topic());
let input_empty = PlugOptionsBuilder::create_input("nothing").build(&tether_agent);
info!("Checking messages every 1s, 10x...");
for i in 1..10 {
info!("#{i}: Checking for messages...");
while let Some((plug_name, message)) = tether_agent.check_messages() {
debug!(
"Received a message topic {} => plug name {}",
message.topic(),
plug_name
);
if &plug_name == input_one.name() {
info!(
"******** INPUT ONE:\n Received a message from plug named \"{}\" on topic {} with length {} bytes",
input_one.name(),
message.topic(),
message.payload().len()
);
}
if &plug_name == input_two.name() {
info!(
"******** INPUT TWO:\n Received a message from plug named \"{}\" on topic {} with length {} bytes",
input_two.name(),
message.topic(),
message.payload().len()
);
// Notice how you must give the from_slice function a type so it knows what to expect
let decoded = from_slice::<CustomMessage>(&message.payload());
match decoded {
Ok(d) => {
info!("Yes, we decoded the MessagePack payload as: {:?}", d);
let CustomMessage { name, id } = d;
debug!("Name is {} and ID is {}", name, id);
}
Err(e) => {
warn!("Failed to decode the payload: {}", e)
}
};
}
if &plug_name == input_empty.name() {
info!(
"******** EMPTY MESSAGE:\n Received a message from plug named \"{}\" on topic {} with length {} bytes",
input_empty.name(),
message.topic(),
message.payload().len()
);
}
}
thread::sleep(Duration::from_millis(1000))
}
}Auto Trait Implementations§
impl RefUnwindSafe for PlugDefinition
impl Send for PlugDefinition
impl Sync for PlugDefinition
impl Unpin for PlugDefinition
impl UnwindSafe for PlugDefinition
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