Skip to content

Instantly share code, notes, and snippets.

@carols10cents
Forked from rust-play/playground.rs
Last active October 31, 2018 00:18
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 carols10cents/0bd87b7bacd0ab52c7b902bda31cf6b8 to your computer and use it in GitHub Desktop.
Save carols10cents/0bd87b7bacd0ab52c7b902bda31cf6b8 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)
}
struct StatusRecord {
id: i64,
text: String,
created_at: Duration,
}
fn save_to_database(text: &str) -> Result<StatusRecord, &'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