[][src]Crate new_home_application_macro

New Home Application (Macro)

This crate provides a macro for deriving the Method trait.


There are a couple of attributes that can be used on the struct and/or fields in the struct

descriptionStructProvides a description for the method
helpStructProvides a help text for an argument/struct field or the method itself


The word "Arguments" describes fields on the Method struct, that are set through the Method::set_arguments method. While you can implement the Method trait by yourself and just handle it on your own, this macro allows you to have the argument attribute on a field which causes the field to be automatically set by the set_arguments method. This however requires the field to have the type serde_json::Value.

The argument attribute also has to have a content, which will become the description for the field.

To set a default value for the argument, there is the default attribute. The content of this attribute will be literally passed to the serde_json::Value::from method. So you will have to wrap strings in quotes. On the other side however, you can easily put a plain number or boolean in there and it will be filled in to the argument.


You can see a full example in the examples/macro-example.rs file, but here you also have a small example for applying the macro onto a struct:

use new_home_application::method::{Method, MethodCallable};
use new_home_application::communication::{MethodCall, MethodResult};
use new_home_application_macro::Method;

use serde::Deserialize;

/// The arguments used in the callable later
struct Arguments {
    /// The word that should be converted
    pub word: String,

    /// Determines if the word will be converted to uppercase
    pub uppercase: bool,

#[description("Can convert a word into uppercase")]
#[help("Will convert the word to uppercase if uppercase flag is set")]
struct ExampleMethod;

impl MethodCallable for ExampleMethod {
    type ArgumentsType = Arguments;

    fn secure_call(&mut self, name: String, arguments: Self::ArgumentsType) -> MethodResult {

The logic for executing whatever the method should do is not implemented here as the Method trait only provides basic information for the method. The logic will be added through the MethodCallable trait which cannot be derived and has to be implemented by yourself.

Derive Macros