Refactor frame to have desired semantics

This commit is contained in:
Josh Mitchell
2020-11-10 20:38:24 +11:00
committed by daniel
parent d559f9e6df
commit 734048d572
6 changed files with 36 additions and 53 deletions

View File

@@ -2,9 +2,9 @@ use crate::*;
use std::rc::Rc;
fn into_iter_inner<T: Trajectory>(mut traj: T) -> TrajectoryIterator<T> {
let num_atoms = traj.get_num_atoms();
let num_atoms = traj.get_num_atoms().map(|n| n as usize);
let frame = match &num_atoms {
Ok(num_atoms) => Frame::with_capacity(*num_atoms),
Ok(num_atoms) => Frame::with_len(*num_atoms),
Err(_) => Frame::new(),
};
TrajectoryIterator {
@@ -58,7 +58,7 @@ impl<T: Trajectory> TrajectoryIterator<T> {
Some(item) => item,
None => {
// caller kept frame. Create new one
self.item = Rc::new(Frame::with_capacity(num_atoms));
self.item = Rc::new(Frame::with_len(num_atoms as usize));
Rc::get_mut(&mut self.item).expect("Could not get mutable access to new Rc")
}
};