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 diff --git a/README.md b/README.md index cd5569b..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,12 +56,10 @@ 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}; -use std::convert::Infallible; #[derive(Deserialize, Serialize, Debug)] #[serde(deny_unknown_fields)] @@ -76,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/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..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,12 +512,12 @@ 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) } } - impl From for $err { - fn from(_value: Infallible) -> Self { + impl From for $err { + fn from(_value: std::convert::Infallible) -> Self { unreachable!(); } }