use satellite_bitcoin::generic::fixed_list::{FixedList, FixedListError};
pub trait IntoShardIndices<const N: usize> {
fn into_indices(self) -> Result<FixedList<usize, N>, FixedListError>;
}
impl<const N: usize> IntoShardIndices<N> for usize {
#[inline]
fn into_indices(self) -> Result<FixedList<usize, N>, FixedListError> {
let mut list = FixedList::new();
list.push(self)?;
Ok(list)
}
}
impl<'b, const N: usize> IntoShardIndices<N> for &'b [usize] {
#[inline]
fn into_indices(self) -> Result<FixedList<usize, N>, FixedListError> {
Ok(FixedList::from_slice(self))
}
}
impl<const N: usize> IntoShardIndices<N> for Vec<usize> {
#[inline]
fn into_indices(self) -> Result<FixedList<usize, N>, FixedListError> {
Ok(FixedList::from_slice(&self))
}
}
impl<const N: usize> IntoShardIndices<N> for FixedList<usize, N> {
#[inline]
fn into_indices(self) -> Result<FixedList<usize, N>, FixedListError> {
Ok(self)
}
}
impl<const N: usize, const M: usize> IntoShardIndices<N> for [usize; M] {
#[inline]
fn into_indices(self) -> Result<FixedList<usize, N>, FixedListError> {
Ok(FixedList::from_slice(&self))
}
}
impl<const N: usize, const M: usize> IntoShardIndices<N> for &FixedList<usize, M> {
#[inline]
fn into_indices(self) -> Result<FixedList<usize, N>, FixedListError> {
Ok(FixedList::from_slice(self.as_slice()))
}
}