pub trait Proxy: Send + Sync {
// Required methods
fn current_username(&self) -> String;
fn set_uservar<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 mut self,
username: &'life1 str,
name: &'life2 str,
value: &'life3 str,
) -> Pin<Box<dyn Future<Output = Result<bool, String>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait;
fn get_uservar<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
username: &'life1 str,
name: &'life2 str,
) -> Pin<Box<dyn Future<Output = String> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
fn get_uservars<'life0, 'life1, 'async_trait>(
&'life0 self,
username: &'life1 str,
) -> Pin<Box<dyn Future<Output = HashMap<String, String>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn set_variable(&mut self, name: &str, value: &str);
fn get_variable(&self, name: &str) -> String;
fn finish(&mut self, output: String) -> Result<SubroutineResult, String>;
}Expand description
Proxy is given as the first argument to RiveScript object macro functions.
It stands in as a ‘proxy’ for the master RiveScript struct. In most RiveScript implementations (in other programming languages), object macros receive a pointer to RiveScript as their first parameter so that they can get/set user variables or manipulate the inner state of the bot to varying degrees.
In Rust, it is not possible to give a mutable borrow of RiveScript to the object macros. Instead, the Proxy stands in for RiveScript and exposes a subset of useful function calls.
Functions like get_uservar should proxy through and get the live value from the RiveScript struct. Functions like set_uservar should cache or ‘stage’ the updates (e.g. using an internal HashMap), and return those values if a subsequent get function asks for them.
Object macros return their final response via the Proxy.finish() method, which (in the SubroutineResult) carries the staged writes to user variables back out so the master RiveScript struct can commit them all after the subroutine has returned.
For object macro subroutines written in Rust, the concrete implementation of this trait can be found in rivescript::macros::proxy::Proxy.