Skip to content

Instantly share code, notes, and snippets.

@mcsee
Last active November 29, 2025 21:10
Show Gist options
  • Select an option

  • Save mcsee/7d729029618f1088697f9fec70a8ba43 to your computer and use it in GitHub Desktop.

Select an option

Save mcsee/7d729029618f1088697f9fec70a8ba43 to your computer and use it in GitHub Desktop.
This gist belongs to Clean Code Cookbook http://cleancodecookbook.com By Maximiliano Contieri http://maximilianocontieri.com
fn load_and_validate(max: usize) -> Result<Vec<Feature>, String> {
let raw: Vec<Result<Feature, Error>> = load_features_from_db();
if raw.len() > max {
return Err(format!(
"too many features: {} > {}",
raw.len(), max
));
}
Ok(raw.into_iter()
.filter_map(|r| r.ok())
.collect())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment