-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract reusable code from doc tests
- Loading branch information
Showing
3 changed files
with
139 additions
and
264 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# use chrono::{DateTime, Utc}; | ||
# use serde::{Deserialize, Serialize}; | ||
# use std::convert::Infallible; | ||
# | ||
# #[derive(Deserialize, Serialize, Debug)] | ||
# #[serde(deny_unknown_fields)] | ||
# struct PersonV1 { | ||
# name: String, | ||
# } | ||
# | ||
# #[derive(Deserialize, Serialize, Debug)] | ||
# #[serde(deny_unknown_fields)] | ||
# struct PersonV2 { | ||
# name: String, | ||
# updated_at: DateTime<Utc>, | ||
# } | ||
# | ||
# // First define how to map from one struct to another | ||
# impl From<PersonV1> for PersonV2 { | ||
# fn from(value: PersonV1) -> Self { | ||
# PersonV2 { | ||
# name: value.name.clone(), | ||
# updated_at: Utc::now(), | ||
# } | ||
# } | ||
# } | ||
# |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# use serde::{Deserialize, Serialize}; | ||
# use std::convert::Infallible; | ||
# | ||
# #[derive(Deserialize, Serialize, Debug)] | ||
# #[serde(deny_unknown_fields)] | ||
# struct PersonV1 { | ||
# name: String, | ||
# title: Option<String>, | ||
# } | ||
# | ||
# #[derive(Deserialize, Serialize, Debug)] | ||
# #[serde(deny_unknown_fields)] | ||
# struct PersonV2 { | ||
# name: String, | ||
# job_title: String, | ||
# } | ||
# | ||
# #[derive(Debug, Eq, PartialEq)] | ||
# struct TitleCannotBeEmpty; | ||
# | ||
# impl From<TitleCannotBeEmpty> for PersonMigrationError { | ||
# fn from(value: TitleCannotBeEmpty) -> Self { | ||
# PersonMigrationError::TitleCannotBeEmpty | ||
# } | ||
# } | ||
# | ||
# #[derive(thiserror::Error, Debug, Eq, PartialEq)] | ||
# enum PersonMigrationError { | ||
# #[error("Title cannot be empty!!!")] | ||
# TitleCannotBeEmpty, | ||
# } | ||
# | ||
# impl TryFrom<PersonV1> for PersonV2 { | ||
# type Error = TitleCannotBeEmpty; | ||
# | ||
# fn try_from(value: PersonV1) -> Result<Self, TitleCannotBeEmpty> { | ||
# if let Some(title) = value.title { | ||
# if title.is_empty() { | ||
# Err(TitleCannotBeEmpty) | ||
# } else { | ||
# Ok(PersonV2 { | ||
# name: value.name, | ||
# job_title: title, | ||
# }) | ||
# } | ||
# } else { | ||
# Err(TitleCannotBeEmpty) | ||
# } | ||
# } | ||
# } |
Oops, something went wrong.