Helper to get an optional request argument.
Synopsis
Declared in <rpc/util.h>
template<typename R>
auto
MaybeArg(std::string_view key) const;
Description
Use this function when the argument is optional and does not have a default value. If the argument is required or has a default value, use Arg instead.
This function only works during m_fun(), i.e., it should only be used in RPC method implementations. It internally checks whether the user‐passed argument isNull() and parses (from JSON) and returns the user‐passed argument, or a falsy value if no argument was passed.
The instantiation of this helper for type R must match the corresponding RPCArg::Type.
Return Value
For trivially copyable types, a std::optional<R> is returned. For other types, a R* pointer to the argument is returned. If the argument is not provided, std::nullopt or a null pointer is returned.
Parameters
Name |
Description |
key |
The name of the argument to fetch. |
See Also
Arg for handling arguments that are required or have a default value.
Created with MrDocs