From 55fca696a870d2cb7154b45d0ac4d264c034f41a Mon Sep 17 00:00:00 2001 From: Bazaah Date: Sun, 27 Mar 2022 10:58:23 +0000 Subject: [PATCH] event/parser: use array_iterator in tests macros --- src/event/parser/mod.rs | 22 ++-------------------- src/event/parser/tests/macros.rs | 2 +- src/event/types.rs | 19 ++++++++++++++++++- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/event/parser/mod.rs b/src/event/parser/mod.rs index 45a722b..e48b664 100644 --- a/src/event/parser/mod.rs +++ b/src/event/parser/mod.rs @@ -34,14 +34,13 @@ //! //! [`Token`]: enum@crate::token::Token -use std::array::IntoIter as ArrayIter; - use crate::{ event::{ error::{ParseError as Error, ParseResult as Result}, state::{Flags, State, StateMachine, O_EMPTY, O_FIRST, O_IMPLICIT, O_NIL}, types::{ - self, Directives, Event, EventData, NodeKind, TagDirectives, DEFAULT_TAGS, EMPTY_SCALAR, + self, array_iterator, Directives, Event, EventData, NodeKind, TagDirectives, + DEFAULT_TAGS, EMPTY_SCALAR, }, }, reader::{PeekReader, Read}, @@ -1301,23 +1300,6 @@ fn tags_to_owned<'a>((handle, prefix): (&Slice<'a>, &Slice<'a>)) (handle.into(), prefix.into()) } -/// Wrapper around IntoIterator::into_iter that works around -/// the hack in `std` which makes our Rust edition's -/// ARRAY.into_iter() postfix call take the array by -/// reference. -/// -/// It appears that ArrayIter::new() has been deprecated in -/// a future rust version (1.59), so this should quiet those -/// errors, when building against stable. -/// -/// If/when we bump the crate's MSRV to >= 1.59 we can -/// remove this function and call the postfix .into_iter() -/// method directly. -fn array_iterator(arr: [T; N]) -> ArrayIter -{ - IntoIterator::into_iter(arr) -} - /// Provides an [`Iterator`] interface to interact with /// [`Event`]s through. #[derive(Debug)] diff --git a/src/event/parser/tests/macros.rs b/src/event/parser/tests/macros.rs index cfe4480..9170c58 100644 --- a/src/event/parser/tests/macros.rs +++ b/src/event/parser/tests/macros.rs @@ -68,7 +68,7 @@ macro_rules! event { types::DEFAULT_VERSION ), tags: std::iter::FromIterator::from_iter( - std::array::IntoIter::new(types::DEFAULT_TAGS).chain(vec![ + types::array_iterator(types::DEFAULT_TAGS).chain(vec![ $($( ($crate::token::Slice::from($handle), $crate::token::Slice::from($prefix)) ),*)? ])), }, diff --git a/src/event/types.rs b/src/event/types.rs index 8849ffc..8d2a1f6 100644 --- a/src/event/types.rs +++ b/src/event/types.rs @@ -419,7 +419,7 @@ impl Default for Directives<'_> { Self { version: DEFAULT_VERSION, - tags: ArrayIter::new(DEFAULT_TAGS).collect(), + tags: array_iterator(DEFAULT_TAGS).collect(), } } } @@ -453,3 +453,20 @@ pub enum ScalarStyle Literal, Folded, } + +/// Wrapper around IntoIterator::into_iter that works around +/// the hack in `std` which makes our Rust edition's +/// ARRAY.into_iter() postfix call take the array by +/// reference. +/// +/// It appears that ArrayIter::new() has been deprecated in +/// a future rust version (1.59), so this should quiet those +/// errors, when building against stable. +/// +/// If/when we bump the crate's MSRV to >= 1.59 we can +/// remove this function and call the postfix .into_iter() +/// method directly. +pub(in crate::event) fn array_iterator(arr: [T; N]) -> ArrayIter +{ + IntoIterator::into_iter(arr) +} -- 2.43.5