-
-
Save carols10cents/0bd87b7bacd0ab52c7b902bda31cf6b8 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains 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
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