Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created October 30, 2018 00:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rust-play/c19f77cf066ca3f67f601ab262df2daa to your computer and use it in GitHub Desktop.
Save rust-play/c19f77cf066ca3f67f601ab262df2daa to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
fn save_status(text: &str) -> Result<i64, &'static str> {
if text.len() > 200 {
return Err("status is too long, must be under 200 bytes");
}
let id = save_to_database(text)?;
// log id to server logs
Ok(id)
}
fn save_to_database(text: &str) -> Result<i64, &'static str> {
Err("database unavailable")
}
fn save_to_database(text: &str) -> Result<i64, DatabaseError> {
Err(DatabaseError::Unavailable)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment