Skip to content

Commit

Permalink
Update Strum (#2088)
Browse files Browse the repository at this point in the history
* Update Strum

* Change log update

* Fetch updates from upstream Strum

* build-tools/update-strum-macros.sh

* Revert "Fetch updates from upstream Strum"

This reverts commit 32cf8f7.

* Update enum_iter.rs

---------

Co-authored-by: Billy Chan <[email protected]>
  • Loading branch information
wyatt-herkamp and billy1624 authored Feb 6, 2024
1 parent 3e149db commit 0adcd3b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## 1.0.0-rc.2 - Pending

### Breaking Changes

* Updated Strum to version 0.26 https://github.com/SeaQL/sea-orm/pull/2088

## 1.0.0-rc.1 - 2024-02-06

### Breaking Changes
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ bigdecimal = { version = "0.3", default-features = false, optional = true }
sea-orm-macros = { version = "1.0.0-rc.1", path = "sea-orm-macros", default-features = false, features = ["strum"] }
sea-query = { version = "0.31.0-rc.3", default-features = false, features = ["thread-safe", "hashable-value", "backend-mysql", "backend-postgres", "backend-sqlite"] }
sea-query-binder = { version = "0.6.0-rc.1", default-features = false, optional = true }
strum = { version = "0.25", default-features = false }
strum = { version = "0.26", default-features = false }
serde = { version = "1.0", default-features = false }
serde_json = { version = "1.0", default-features = false, optional = true }
sqlx = { version = "0.7", default-features = false, optional = true }
Expand Down
8 changes: 8 additions & 0 deletions build-tools/update-strum-macros.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
rm -rf sea-orm-macros/src/strum/helpers
rm -rf sea-orm-macros/src/strum/enum_iter.rs

cp -r ../strum/strum_macros/src/helpers sea-orm-macros/src/strum/helpers
cp -r ../strum/strum_macros/src/macros/enum_iter.rs sea-orm-macros/src/strum/enum_iter.rs

sed -i 's/crate::helpers::{*/super::helpers::{/' sea-orm-macros/src/strum/enum_iter.rs
sed -i 's/parse_quote!(::strum)*/parse_quote!(sea_orm::strum)/' sea-orm-macros/src/strum/helpers/type_props.rs
18 changes: 10 additions & 8 deletions sea-orm-macros/src/strum/enum_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ pub fn enum_iter_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
#[allow(
missing_copy_implementations,
)]
#vis struct #iter_name #ty_generics {
#vis struct #iter_name #impl_generics {
idx: usize,
back_idx: usize,
marker: ::core::marker::PhantomData #phantom_data,
}

impl #impl_generics core::fmt::Debug for #iter_name #ty_generics #where_clause {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
impl #impl_generics ::core::fmt::Debug for #iter_name #ty_generics #where_clause {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
// We don't know if the variants implement debug themselves so the only thing we
// can really show is how many elements are left.
f.debug_struct(#iter_name_debug_struct)
Expand All @@ -91,7 +91,7 @@ pub fn enum_iter_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
}

impl #impl_generics #iter_name #ty_generics #where_clause {
fn get(&self, idx: usize) -> Option<#name #ty_generics> {
fn get(&self, idx: usize) -> ::core::option::Option<#name #ty_generics> {
match idx {
#(#arms),*
}
Expand All @@ -112,16 +112,16 @@ pub fn enum_iter_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
impl #impl_generics Iterator for #iter_name #ty_generics #where_clause {
type Item = #name #ty_generics;

fn next(&mut self) -> Option<<Self as Iterator>::Item> {
fn next(&mut self) -> ::core::option::Option<<Self as Iterator>::Item> {
self.nth(0)
}

fn size_hint(&self) -> (usize, Option<usize>) {
fn size_hint(&self) -> (usize, ::core::option::Option<usize>) {
let t = if self.idx + self.back_idx >= #variant_count { 0 } else { #variant_count - self.idx - self.back_idx };
(t, Some(t))
}

fn nth(&mut self, n: usize) -> Option<<Self as Iterator>::Item> {
fn nth(&mut self, n: usize) -> ::core::option::Option<<Self as Iterator>::Item> {
let idx = self.idx + n + 1;
if idx + self.back_idx > #variant_count {
// We went past the end of the iterator. Freeze idx at #variant_count
Expand All @@ -143,7 +143,7 @@ pub fn enum_iter_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
}

impl #impl_generics DoubleEndedIterator for #iter_name #ty_generics #where_clause {
fn next_back(&mut self) -> Option<<Self as Iterator>::Item> {
fn next_back(&mut self) -> ::core::option::Option<<Self as Iterator>::Item> {
let back_idx = self.back_idx + 1;

if self.idx + back_idx > #variant_count {
Expand All @@ -159,6 +159,8 @@ pub fn enum_iter_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
}
}

impl #impl_generics ::core::iter::FusedIterator for #iter_name #ty_generics #where_clause { }

impl #impl_generics Clone for #iter_name #ty_generics #where_clause {
fn clone(&self) -> #iter_name #ty_generics {
#iter_name {
Expand Down

0 comments on commit 0adcd3b

Please sign in to comment.