avm2: Use the actual `FromIterator` trait
This commit is contained in:
parent
1baadb93c2
commit
05dc538a25
|
@ -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<I, V>(values: I) -> Self
|
||||
where
|
||||
I: Iterator<Item = V>,
|
||||
V: Into<Value<'gc>>,
|
||||
{
|
||||
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<Option<Value<'gc>>>) -> Self {
|
||||
Self { storage }
|
||||
|
@ -182,3 +170,17 @@ impl<'gc> ArrayStorage<'gc> {
|
|||
.splice(range, replace_with.into_iter().map(Some))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'gc, V> FromIterator<V> for ArrayStorage<'gc>
|
||||
where
|
||||
V: Into<Value<'gc>>,
|
||||
{
|
||||
fn from_iter<I>(values: I) -> Self
|
||||
where
|
||||
I: IntoIterator<Item = V>,
|
||||
{
|
||||
let storage = values.into_iter().map(|v| Some(v.into())).collect();
|
||||
|
||||
Self { storage }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue