Previously, calling/deploying with Session required that all arguments are converted to String. This was onerous to add ".to_string()" for string literals. Instead we accept anything that is AsRef<str> + Debug (the Debug bound is required for encoding), which accepts now String and &str.
Since often messages don't have arguments, passing &[] requires specifying the explicit type. For that we define auxiliary constant NO_ARGS which is just empty &[String].
Alternatively, we could be less restrictive and require only Debug or Into<String> + Debug. However, this might introduce problems / confusion for non-homogenic argument lists. Consider:
fn message1(account: AccountId) {..}
fn message2(account: AccountId, value: u128) {..}
let account: AccountId = ...;
let value: u128 = ...;
session.call("message1", &[account]) // works fine
session.call("message1", &[account.to_string()]) // works fine as well
session.call("message", &[account, value]) // this won't work - slice must contain values of the same type
session.call("message", &[account.to_string(), value.to_string()]) // we have to convert to string anyway
Previously, calling/deploying with
Session
required that all arguments are converted toString
. This was onerous to add".to_string()"
for string literals. Instead we accept anything that isAsRef<str> + Debug
(theDebug
bound is required for encoding), which accepts nowString
and&str
.Since often messages don't have arguments, passing
&[]
requires specifying the explicit type. For that we define auxiliary constantNO_ARGS
which is just empty&[String]
.Alternatively, we could be less restrictive and require only
Debug
orInto<String> + Debug
. However, this might introduce problems / confusion for non-homogenic argument lists. Consider: