Last active
April 24, 2019 18:00
-
-
Save anowell/c4ffc76ecc9f4315f2a38e106f4eae3f to your computer and use it in GitHub Desktop.
Rust Algo Example
This file contains hidden or 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 | |
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