Last active
April 17, 2019 17:46
-
-
Save anowell/542aabde17fa8e56b5be68de46f6ac1e to your computer and use it in GitHub Desktop.
Rust Algo Example 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use algorithmia::prelude::*; | |
use serde::{Serialize, Deserialize}; | |
use std::error::Error; | |
#[derive(Deserialize)] | |
pub struct Input { name: String } | |
#[derive(Serialize)] | |
struct Output { msg: String } | |
// Entry point for each API call | |
pub fn apply(input: Input, context: &File) -> Result<Output, Box<Error>> { | |
Ok(Output { | |
msg: format!("Hello {}", input.name), | |
}) | |
} | |
pub fn download_model() -> Result<File, Box<Error>> { | |
// imagine downloading file and returning the File handle | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::error::Error; | |
fn main() -> Result<(), Box<Error>> { | |
let model = algorithm::download_model()?; | |
let algo = algorithmia::algorithm_handler(|input| algorithm::apply(input, model)); | |
algo.run() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment