Skip to content

Commit

Permalink
feat!: impl trait clone.
Browse files Browse the repository at this point in the history
  • Loading branch information
tokcum committed Jun 21, 2023
1 parent 277fa71 commit cd56408
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -132,8 +132,9 @@ Demonstrate capabilities!

## Version 0.2.0 (planned)
- Support iterators for `Sequence`
- Support the trait `Clone`

## Version 0.1.0 (in progress)
## Version 0.1.0 (delivered)
- Initial release.
- Examples to demonstrate the power of fraction based positioning.
- Examples showing how to use this library with SQlite.
Expand Down
17 changes: 17 additions & 0 deletions src/sequence.rs
Expand Up @@ -159,6 +159,23 @@ impl<T> IndexMut<usize> for Sequence<T> {
}
}

impl<T: Clone> Clone for Sequence<T> {
fn clone(&self) -> Self {
let mut n = 0;
let mut seq: Sequence<T> = Sequence::new();

while n < self.len() {
let pos = self.positions[n];
let element = self.elements[n].clone();

seq.insert_at(pos, element);
n += 1;
}

seq
}
}

/*
impl<T> Iterator for Sequence<T> {
type Item = (u64, u64, T);
Expand Down
9 changes: 9 additions & 0 deletions src/tests/sequence/tests.rs
Expand Up @@ -191,4 +191,13 @@ mod tests {

assert_eq!(seq[0], "_H".to_string());
}

#[test]
fn test_trait_impl_clone() {
let seq = setup_seq_abc();
let seq2 = seq.clone();

assert_eq!(seq.len(), seq2.len());
assert_eq!(seq, seq2);
}
}

0 comments on commit cd56408

Please sign in to comment.