1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use super::{
    PrimaryTableIndex, ScopeName, SecondaryTableName, Table, TableName,
};
use crate::AccountName;
use core::marker::PhantomData;

/// TODO docs
#[derive(Copy, Clone, Debug)]
pub struct SecondaryTableIndex<K, T>
where
    T: Table,
{
    /// TODO docs
    pub code: AccountName,
    /// TODO docs
    pub scope: ScopeName,
    /// TODO docs
    pub table: SecondaryTableName,
    /// TODO docs
    _data: PhantomData<(K, T)>,
}

impl<K, T> SecondaryTableIndex<K, T>
where
    T: Table,
{
    /// TODO docs
    #[inline]
    pub fn new<C, S, N>(code: C, scope: S, name: N, index: usize) -> Self
    where
        C: Into<AccountName>,
        S: Into<ScopeName>,
        N: Into<TableName>,
    {
        Self {
            code: code.into(),
            scope: scope.into(),
            table: SecondaryTableName::new(name.into(), index),
            _data: PhantomData,
        }
    }

    /// TODO docs
    #[must_use]
    pub fn primary_index(&self) -> PrimaryTableIndex<T> {
        PrimaryTableIndex::new(self.code, self.scope)
    }
}