Skip to content

Instantly share code, notes, and snippets.

@anowell
Last active April 24, 2019 18:00
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/c4ffc76ecc9f4315f2a38e106f4eae3f to your computer and use it in GitHub Desktop.
Save anowell/c4ffc76ecc9f4315f2a38e106f4eae3f to your computer and use it in GitHub Desktop.
Rust Algo Example
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
fn apply(input: Input, context: &mut Vec<u8>) -> Result<Output, Box<Error>> {
Ok(Output {
msg: format!("Hello {}", input.name),
})
}
fn download_model() -> Result<Vec<u8>, Box<Error>> {
// imagine downloading file into a buffer and returning it
}
fn main() -> Result<(), Box<Error>> {
let algo = AlgorithmHandler::with_load_function(apply, download_model);
algo.run()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment