header: FileHeader,
extender: Option<ExtendableIndicator>,
origin: isize,
- items: Vec<Type::Item>,
+ items: Vec<(String, Type::Item)>,
}
impl<Type: FileType, Source: FileDataSource> FileContents<Type,Source> {
for id in ids {
let item = Type::get_from_client(&id, client)
.expect("Any id stored in a Feed should also be cached");
- self.items.push(item);
+ self.items.push((id.to_owned(), item));
}
}
}
} else {
let index = self.phys_index(index);
- &self.items[index]
+ &self.items[index].1
}
}
+
+ fn index_of_id(&self, id: &str) -> Option<isize> {
+ // We can't do anything efficient like binary search, because
+ // our ids might not be in any sensible order. (If they're,
+ // say, a list of users that took an action, the ids' natural
+ // order would be user creation date, but here they'd be
+ // ordered by when each user did the thing.)
+ self.items.iter().position(|item| item.0 == id)
+ .map(|u| (u as isize) + self.origin)
+ }
}
#[derive(Debug, PartialEq, Eq, Clone, Copy)]