How to create a Rust method that doesn't have a return value?

Hi Gang,

This may be quite a simple one, but I am just getting back into Rust again and wanted to create a simple test method to call and test my new Signal code in the HoloNET .NET/Unity client I am currently upgrading to support Signals and other cool new features.

I have this in my zome:

    #[zome_fn("hc_public")]

        fn test_signals() -> ZomeApiResult<bool> {

            let message = "Hello World".to_string();

            hdk::emit_signal("message_received", SignalPayload{message});

            Ok(true)

        }

But I am getting this error back from the Rust compiler:

error: unused `std::result::Result` that must be used
  --> src/lib.rs:64:9
   |
64 |         hdk::emit_signal("message_received", SignalPayload{message});
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: `-D unused-must-use` implied by `-D warnings`
   = note: this `Result` may be an `Err` variant, which should be handled

error: aborting due to previous error

error: could not compile `our_world_core`.

Any help would be really appreciated.

Many thanks,
David.

Try:
let _ = hdk::emit_signal("message_received", SignalPayload{message});

Or:
hdk::emit_signal("message_received", SignalPayload{message}).ok();

1 Like

Thank you, that worked! :slight_smile: