pub fn extract_data(content: String) -> Result<String, ApplicationError> { match content.find("head") { Some(start) => match content.find("tail") { Some(end) => { Ok(content[start..end]) }, None => Err(ApplicationError::MissingTail), }, None => Err(ApplicationError::MissingHead) } } +++++++++++++++++++++++++++++++++++++++++++ pub fn extract_data(content: String) -> Result<String, ApplicationError> { let start = content .find("head") .ok_or_else(|| ApplicationError::MissingHead)?; let end = content .find("tail") .ok_or_else(|| ApplicationError::MissingTail)?; Ok(content[start..end]) } 我喜欢第二种 |