Skip to content

Commit 1a8be59

Browse files
dovahcrowtj
authored andcommitted
update rust example (#851)
1 parent c3655df commit 1a8be59

File tree

2 files changed

+17
-27
lines changed

2 files changed

+17
-27
lines changed

_examples/rust/functions/hello/Cargo.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ version = "0.1.0"
44
authors = ["Your Name <your [email protected]>"]
55

66
[dependencies]
7-
rust-apex = "0.2"
8-
serde_json = "0.9"
7+
rust-apex = "0.3"
8+
serde_json = "1"
9+
failure = "0.1"
910

+14-25
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,21 @@
11
extern crate rust_apex;
2+
#[macro_use]
23
extern crate serde_json;
4+
extern crate failure;
35

4-
use std::error::Error;
5-
use std::collections::BTreeMap;
6-
use std::fmt::{Display, Formatter, Error as FmtError};
7-
8-
use serde_json::{Value, to_value};
9-
10-
#[derive(Debug)]
11-
struct DummyError;
12-
13-
impl Display for DummyError {
14-
fn fmt(&self, f: &mut Formatter) -> Result<(), FmtError> {
15-
write!(f, "{:?}", self)
16-
}
17-
}
18-
19-
impl Error for DummyError {
20-
fn description(&self) -> &str {
21-
"dummy"
22-
}
23-
}
6+
use failure::{Compat, Error};
7+
use serde_json::{to_value, Value};
8+
use rust_apex::Context;
249

2510
fn main() {
26-
rust_apex::run::<_, _, DummyError, _>(|input: Value, c: rust_apex::Context| {
27-
let mut bt = BTreeMap::new();
28-
bt.insert("c", to_value(&c).unwrap());
29-
bt.insert("i", input);
30-
Ok(bt)
11+
rust_apex::run::<_, _, Compat<Error>, _>(|input: Value, c: Context| {
12+
Ok(json!({
13+
"name": to_value(&c).unwrap(),
14+
"age": input,
15+
"phones": [
16+
"+44 1234567",
17+
"+44 2345678"
18+
]
19+
}))
3120
});
3221
}

0 commit comments

Comments
 (0)