compact_genome/implementation/
handle_sequence_store.rs1use std::marker::PhantomData;
6
7use crate::interface::{
8 alphabet::{Alphabet, AlphabetError},
9 sequence::{GenomeSequence, OwnedGenomeSequence},
10 sequence_store::SequenceStore,
11};
12
13#[derive(Default, Clone, Eq, PartialEq, Debug)]
17pub struct HandleSequenceStore<AlphabetType, SequenceType, SubsequenceType: ?Sized> {
18 phantom_data: PhantomData<(AlphabetType, SequenceType, SubsequenceType)>,
19}
20
21impl<AlphabetType, SequenceType, SubsequenceType: ?Sized>
22 HandleSequenceStore<AlphabetType, SequenceType, SubsequenceType>
23{
24 pub fn new() -> Self {
26 Self {
27 phantom_data: Default::default(),
28 }
29 }
30}
31
32impl<
33 AlphabetType: Alphabet,
34 SequenceType: OwnedGenomeSequence<AlphabetType, SubsequenceType>,
35 SubsequenceType: GenomeSequence<AlphabetType, SubsequenceType> + ?Sized,
36 > SequenceStore<AlphabetType>
37 for HandleSequenceStore<AlphabetType, SequenceType, SubsequenceType>
38{
39 type Handle = SequenceType;
40 type SequenceRef = SubsequenceType;
41
42 fn add<
43 Sequence: GenomeSequence<AlphabetType, Subsequence> + ?Sized,
44 Subsequence: GenomeSequence<AlphabetType, Subsequence> + ?Sized,
45 >(
46 &mut self,
47 s: &Sequence,
48 ) -> Self::Handle {
49 Self::Handle::from_iter(s.iter().cloned())
50 }
51
52 fn add_from_iter(
53 &mut self,
54 iter: impl IntoIterator<Item = <AlphabetType as Alphabet>::CharacterType>,
55 ) -> Self::Handle {
56 Self::Handle::from_iter(iter)
57 }
58
59 fn add_from_iter_u8<IteratorType: IntoIterator<Item = u8>>(
60 &mut self,
61 iter: IteratorType,
62 ) -> Result<Self::Handle, AlphabetError> {
63 Self::Handle::from_iter_u8(iter)
64 }
65
66 fn get<'this: 'result, 'handle: 'result, 'result>(
67 &'this self,
68 handle: &'handle Self::Handle,
69 ) -> &'result Self::SequenceRef {
70 handle.as_genome_subsequence()
71 }
72}