Try to build the change header, returning an error if invalid. This is a non-panicking alternative to `build()`.
(self)
| 387 | /// |
| 388 | /// This is a non-panicking alternative to `build()`. |
| 389 | pub fn try_build(self) -> Result<ChangeHeader, &'static str> { |
| 390 | if self.message.is_none() || self.message.as_ref().map(|m| m.is_empty()).unwrap_or(true) { |
| 391 | return Err("Change message is required"); |
| 392 | } |
| 393 | |
| 394 | Ok(ChangeHeader { |
| 395 | message: self.message.unwrap(), |
| 396 | description: self.description, |
| 397 | timestamp: self.timestamp.unwrap_or_else(Utc::now), |
| 398 | authors: self.authors, |
| 399 | }) |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | #[cfg(test)] |