Skip to content

Instantly share code, notes, and snippets.

@anowell
Last active April 17, 2019 17:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anowell/542aabde17fa8e56b5be68de46f6ac1e to your computer and use it in GitHub Desktop.
Save anowell/542aabde17fa8e56b5be68de46f6ac1e to your computer and use it in GitHub Desktop.
Rust Algo Example 2
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
}
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