From 05dc538a258b6a651b66a3d9404d725be891a95b Mon Sep 17 00:00:00 2001 From: David Wendt Date: Mon, 15 Mar 2021 21:39:57 -0400 Subject: [PATCH] avm2: Use the actual `FromIterator` trait --- core/src/avm2/array.rs | 28 +++++++++++++++------------- core/src/html/text_format.rs | 1 + 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/core/src/avm2/array.rs b/core/src/avm2/array.rs index 2596d78c7..aaa1f83b9 100644 --- a/core/src/avm2/array.rs +++ b/core/src/avm2/array.rs @@ -2,7 +2,7 @@ use crate::avm2::value::Value; use gc_arena::Collect; -use std::iter::ExactSizeIterator; +use std::iter::{ExactSizeIterator, FromIterator}; use std::ops::RangeBounds; /// The array storage portion of an array object. @@ -39,18 +39,6 @@ impl<'gc> ArrayStorage<'gc> { Self { storage } } - /// Convert any iterable stream of values or value-like items into array - /// storage. - pub fn from_iter(values: I) -> Self - where - I: Iterator, - V: Into>, - { - let storage = values.map(|v| Some(v.into())).collect(); - - Self { storage } - } - /// Wrap an existing storage Vec in an `ArrayStorage`. pub fn from_storage(storage: Vec>>) -> Self { Self { storage } @@ -182,3 +170,17 @@ impl<'gc> ArrayStorage<'gc> { .splice(range, replace_with.into_iter().map(Some)) } } + +impl<'gc, V> FromIterator for ArrayStorage<'gc> +where + V: Into>, +{ + fn from_iter(values: I) -> Self + where + I: IntoIterator, + { + let storage = values.into_iter().map(|v| Some(v.into())).collect(); + + Self { storage } + } +} diff --git a/core/src/html/text_format.rs b/core/src/html/text_format.rs index b8e5f24a4..50072c73f 100644 --- a/core/src/html/text_format.rs +++ b/core/src/html/text_format.rs @@ -17,6 +17,7 @@ use crate::xml::{Step, XmlDocument, XmlName, XmlNode}; use gc_arena::{Collect, MutationContext}; use std::borrow::Cow; use std::cmp::{min, Ordering}; +use std::iter::FromIterator; use std::sync::Arc; /// Replace HTML entities with their equivalent characters.