pub struct JavaScript { /* private fields */ }Expand description
Holds an apple flavoured JavaScript
Implementations§
Source§impl JavaScript
impl JavaScript
Sourcepub fn new(code: &str) -> JavaScript
pub fn new(code: &str) -> JavaScript
Creates a new script from the given code.
Examples found in repository?
examples/basic.rs (lines 21-29)
20fn main() {
21 let script = JavaScript::new("
22 var App = Application('Finder');
23 App.includeStandardAdditions = true;
24 return App.displayAlert($params.title, {
25 message: $params.message,
26 'as': $params.alert_type,
27 buttons: $params.buttons,
28 });
29 ");
30
31 let rv: AlertResult = script.execute_with_params(AlertParams {
32 title: "Shit is on fire!".into(),
33 message: "What is happening".into(),
34 alert_type: "critical".into(),
35 buttons: vec![
36 "Show details".into(),
37 "Ignore".into(),
38 ]
39 }).unwrap();
40
41 println!("You clicked '{}'", rv.button);
42}Sourcepub fn execute<'a, D: DeserializeOwned>(&self) -> Result<D, Error>
pub fn execute<'a, D: DeserializeOwned>(&self) -> Result<D, Error>
Executes the script and does not pass any arguments.
Sourcepub fn execute_with_params<'a, S: Serialize, D: DeserializeOwned>(
&self,
params: S,
) -> Result<D, Error>
pub fn execute_with_params<'a, S: Serialize, D: DeserializeOwned>( &self, params: S, ) -> Result<D, Error>
Executes the script and passes the provided arguments.
Examples found in repository?
examples/basic.rs (lines 31-39)
20fn main() {
21 let script = JavaScript::new("
22 var App = Application('Finder');
23 App.includeStandardAdditions = true;
24 return App.displayAlert($params.title, {
25 message: $params.message,
26 'as': $params.alert_type,
27 buttons: $params.buttons,
28 });
29 ");
30
31 let rv: AlertResult = script.execute_with_params(AlertParams {
32 title: "Shit is on fire!".into(),
33 message: "What is happening".into(),
34 alert_type: "critical".into(),
35 buttons: vec![
36 "Show details".into(),
37 "Ignore".into(),
38 ]
39 }).unwrap();
40
41 println!("You clicked '{}'", rv.button);
42}Auto Trait Implementations§
impl Freeze for JavaScript
impl RefUnwindSafe for JavaScript
impl Send for JavaScript
impl Sync for JavaScript
impl Unpin for JavaScript
impl UnwindSafe for JavaScript
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more