JavaScript

Struct JavaScript 

Source
pub struct JavaScript { /* private fields */ }
Expand description

Holds an apple flavoured JavaScript

Implementations§

Source§

impl JavaScript

Source

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}
Source

pub fn execute<'a, D: DeserializeOwned>(&self) -> Result<D, Error>

Executes the script and does not pass any arguments.

Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.