From 1c813cb234e64fa42601094b0e39d0dc83494911 Mon Sep 17 00:00:00 2001 From: Schneems Date: Thu, 19 Dec 2024 22:28:17 -0600 Subject: [PATCH 1/3] No need to import `use std::convert::Infallible;` --- README.md | 1 - src/fixtures/personV1_V2.txt | 1 - src/fixtures/try_personV1_V2.txt | 1 - src/lib.rs | 4 ++-- 4 files changed, 2 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index cd5569b..b33f765 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,6 @@ use serde::de::Deserializer; use serde::{Deserialize, Serialize}; use chrono::{DateTime, Utc}; -use std::convert::Infallible; #[derive(Deserialize, Serialize, Debug)] #[serde(deny_unknown_fields)] diff --git a/src/fixtures/personV1_V2.txt b/src/fixtures/personV1_V2.txt index 0c265fe..58da1f0 100644 --- a/src/fixtures/personV1_V2.txt +++ b/src/fixtures/personV1_V2.txt @@ -1,6 +1,5 @@ # use chrono::{DateTime, Utc}; # use serde::{Deserialize, Serialize}; -# use std::convert::Infallible; # # #[derive(Deserialize, Serialize, Debug)] # #[serde(deny_unknown_fields)] diff --git a/src/fixtures/try_personV1_V2.txt b/src/fixtures/try_personV1_V2.txt index 5294f98..9efe46d 100644 --- a/src/fixtures/try_personV1_V2.txt +++ b/src/fixtures/try_personV1_V2.txt @@ -1,5 +1,4 @@ # use serde::{Deserialize, Serialize}; -# use std::convert::Infallible; # # #[derive(Deserialize, Serialize, Debug)] # #[serde(deny_unknown_fields)] diff --git a/src/lib.rs b/src/lib.rs index e8c61e3..095d462 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -525,8 +525,8 @@ macro_rules! try_migrate_deserializer_chain { $deser(input) } } - impl From for $err { - fn from(_value: Infallible) -> Self { + impl From for $err { + fn from(_value: std::convert::Infallible) -> Self { unreachable!(); } } From 7a33913dfaa649f9861f7612623e305067569137 Mon Sep 17 00:00:00 2001 From: Schneems Date: Thu, 19 Dec 2024 22:35:21 -0600 Subject: [PATCH 2/3] No need to import `use serde::de::Deserializer;` --- README.md | 10 ++++------ src/lib.rs | 31 +++++++++++-------------------- 2 files changed, 15 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index b33f765..5305ea4 100644 --- a/README.md +++ b/README.md @@ -38,12 +38,11 @@ Once defined, invoke migrations via the `try_from_str_migrations` associated fun To define migrations you can use a macro like this: ```ignore -use magic_migrate::{TryMigrate, try_migrate_deserializer_chain}; -use serde::de::Deserializer; +use magic_migrate::TryMigrate; // ... -try_migrate_deserializer_chain!( +magic_migrate::try_migrate_deserializer_chain!( deserializer: toml::Deserializer::new, error: PersonMigrationError, chain: [PersonV1, PersonV2], @@ -57,8 +56,7 @@ try_migrate_deserializer_chain!( Full example: ```rust -use magic_migrate::{TryMigrate, try_migrate_deserializer_chain}; -use serde::de::Deserializer; +use magic_migrate::TryMigrate; use serde::{Deserialize, Serialize}; use chrono::{DateTime, Utc}; @@ -75,7 +73,7 @@ struct PersonV2 { name: String, updated_at: DateTime } -try_migrate_deserializer_chain!( // <=========== HERE +magic_migrate::try_migrate_deserializer_chain!( // <=========== HERE deserializer: toml::Deserializer::new, error: PersonMigrationError, chain: [PersonV1, PersonV2], diff --git a/src/lib.rs b/src/lib.rs index 095d462..ccd0bcc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,6 @@ #![doc = include_str!("../README.md")] use serde::de::DeserializeOwned; -use serde::Deserializer; use std::any::{Any, TypeId}; use std::fmt::{Debug, Display}; @@ -40,7 +39,6 @@ use std::fmt::{Debug, Display}; /// /// ```rust /// use magic_migrate::Migrate; -/// use serde::de::Deserializer; /// #[doc = include_str!("fixtures/personV1_V2.txt")] /// @@ -54,7 +52,7 @@ use std::fmt::{Debug, Display}; /// impl Migrate for PersonV1 { /// type From = Self; /// -/// fn deserializer<'de>(input: &str) -> impl Deserializer<'de> { +/// fn deserializer<'de>(input: &str) -> impl serde::de::Deserializer<'de> { /// toml::Deserializer::new(input) /// } /// } @@ -66,7 +64,7 @@ use std::fmt::{Debug, Display}; /// impl Migrate for PersonV2 { /// type From = PersonV1; /// -/// fn deserializer<'de>(input: &str) -> impl Deserializer<'de> { +/// fn deserializer<'de>(input: &str) -> impl serde::de::Deserializer<'de> { /// ::From::deserializer(input) /// } /// } @@ -91,7 +89,7 @@ use std::fmt::{Debug, Display}; pub trait Migrate: From + Any + DeserializeOwned + Debug { type From: Migrate; - fn deserializer<'de>(input: &str) -> impl Deserializer<'de>; + fn deserializer<'de>(input: &str) -> impl serde::de::Deserializer<'de>; fn from_str_migrations(input: &str) -> Option { if let Ok(instance) = Self::deserialize(Self::deserializer(input)) { @@ -128,8 +126,6 @@ pub trait Migrate: From + Any + DeserializeOwned + Debug { /// /// ```rust /// use magic_migrate::TryMigrate; -/// use serde::de::Deserializer; -/// #[doc = include_str!("fixtures/try_personV1_V2.txt")] /// /// // First define a migration on the beginning of the chain @@ -143,7 +139,7 @@ pub trait Migrate: From + Any + DeserializeOwned + Debug { /// type TryFrom = Self; /// type Error = PersonMigrationError; /// -/// fn deserializer<'de>(input: &str) -> impl Deserializer<'de> { +/// fn deserializer<'de>(input: &str) -> impl serde::de::Deserializer<'de> { /// toml::Deserializer::new(input) /// } /// } @@ -165,7 +161,7 @@ pub trait Migrate: From + Any + DeserializeOwned + Debug { /// type TryFrom = PersonV1; /// type Error = PersonMigrationError; /// -/// fn deserializer<'de>(input: &str) -> impl Deserializer<'de> { +/// fn deserializer<'de>(input: &str) -> impl serde::de::Deserializer<'de> { /// ::TryFrom::deserializer(input) /// } /// } @@ -195,7 +191,7 @@ pub trait TryMigrate: TryFrom + Any + DeserializeOwned + Debug { /// Tell magic migrate how you want to deserialize your strings /// into structs - fn deserializer<'de>(input: &str) -> impl Deserializer<'de>; + fn deserializer<'de>(input: &str) -> impl serde::de::Deserializer<'de>; type Error: From<::TryFrom>>::Error> + From<<::TryFrom as TryMigrate>::Error> @@ -228,7 +224,7 @@ where { type TryFrom = ::From; - fn deserializer<'de>(input: &str) -> impl Deserializer<'de> { + fn deserializer<'de>(input: &str) -> impl serde::de::Deserializer<'de> { ::deserializer(input) } @@ -258,7 +254,7 @@ macro_rules! migrate_link { impl Migrate for $b { type From = $a; - fn deserializer<'de>(input: &str) -> impl Deserializer<'de> { + fn deserializer<'de>(input: &str) -> impl serde::de::Deserializer<'de> { ::From::deserializer(input) } } @@ -285,7 +281,6 @@ macro_rules! migrate_link { /// /// ```no_run /// use magic_migrate::Migrate; -/// use serde::de::Deserializer; #[doc = include_str!("fixtures/personV1_V2.txt")] /// /// // - Link PersonV1 => PersonV1 and set the toml deserializer @@ -335,7 +330,7 @@ macro_rules! try_migrate_link { type TryFrom = $a; type Error = <::TryFrom as TryMigrate>::Error; - fn deserializer<'de>(input: &str) -> impl Deserializer<'de> { + fn deserializer<'de>(input: &str) -> impl serde::de::Deserializer<'de> { ::TryFrom::deserializer(input) } } @@ -358,8 +353,6 @@ macro_rules! try_migrate_link { /// /// ```rust /// use magic_migrate::TryMigrate; -/// use serde::Deserializer; -/// #[doc = include_str!("fixtures/try_personV1_V2.txt")] /// /// magic_migrate::try_migrate_toml_chain!( @@ -421,7 +414,6 @@ macro_rules! try_migrate_toml_chain { /// /// ```rust /// use magic_migrate::Migrate; -/// use serde::de::Deserializer; #[doc = include_str!("fixtures/personV1_V2.txt")] /// /// magic_migrate::migrate_deserializer_chain!( @@ -447,7 +439,7 @@ macro_rules! migrate_deserializer_chain { impl Migrate for $a { type From = Self; - fn deserializer<'de>(input: &str) -> impl Deserializer<'de> { + fn deserializer<'de>(input: &str) -> impl serde::de::Deserializer<'de> { $deser(input) } } @@ -484,7 +476,6 @@ macro_rules! migrate_deserializer_chain { /// /// ```rust /// use magic_migrate::TryMigrate; -/// use serde::Deserializer; #[doc = include_str!("fixtures/try_personV1_V2.txt")] /// /// magic_migrate::try_migrate_deserializer_chain!( @@ -521,7 +512,7 @@ macro_rules! try_migrate_deserializer_chain { type TryFrom = Self; type Error = $err; - fn deserializer<'de>(input: &str) -> impl Deserializer<'de> { + fn deserializer<'de>(input: &str) -> impl serde::de::Deserializer<'de> { $deser(input) } } From 728076d7ea494a3139c466e03494aa87d5889bfb Mon Sep 17 00:00:00 2001 From: Schneems Date: Thu, 19 Dec 2024 22:39:36 -0600 Subject: [PATCH 3/3] Add URL --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a1729d5..48c4b88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,10 @@ ## Unreleased +- Fix: Macro users no longer need to import `std::convert::Infallible` or `serde::de::Deserializer` (https://github.com/schneems/magic_migrate/pull/14) + ## 1.0.0 - 2024/12/18 -- Change: `TryMigrate::Error` must now be `Display` + `Debug` () +- Change: `TryMigrate::Error` must now be `Display` + `Debug` (https://github.com/schneems/magic_migrate/pull/11) ## 0.2.1 - 2024/12/12