Documentation
/*
==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--

SJ

Copyright (C) 2019-2025  Anonymous

There are several releases over multiple years,
they are listed as ranges, such as: "2019-2025".

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/>.

::--::--::--::--::--::--::--::--::--::--::--::--::--::--::--::--
*/

//! # Keys in Object

mod inner;

use {
    core::ops::RangeTo,
    self::inner::Inner,
};

/// # Object Indexes
///
/// You rarely use this directly. See [shortcuts for objects][enum:Json#shortcuts-for-object] for examples.
///
/// [enum:Json#shortcuts-for-object]: enum.Json.html#shortcuts-for-object
#[derive(Debug)]
pub struct ObjectIndexes<'a, const N: usize> {

    inner: Inner<'a, N>,

}

impl<const N: usize> ObjectIndexes<'_, N> {

    /// # Makes new iterator
    pub (crate) fn iter(&self) -> impl Iterator<Item=&str> {
        let result = match &self.inner {
            Inner::Slice(slice) => slice.iter(),
            Inner::Array(array) => array.iter(),
        };
        result.map(|s| *s)
    }

    /// # Length
    pub (crate) fn len(&self) -> usize {
        match &self.inner {
            Inner::Slice(slice) => slice.len(),
            Inner::Array(array) => array.len(),
        }
    }

    /// # Indexing with `RangeTo` (for logging)
    pub (crate) fn index_with_range_to(&self, range: RangeTo<usize>) -> &[&str] {
        &self.inner[range]
    }

}

impl<'a> From<&'a str> for ObjectIndexes<'a, 1> {

    fn from(key: &'a str) -> Self {
        Self {
            inner: Inner::Array([key]),
        }
    }

}

impl<'a, const N: usize> From<[&'a str; N]> for ObjectIndexes<'a, N> {

    fn from(keys: [&'a str; N]) -> Self {
        Self {
            inner: Inner::Array(keys),
        }
    }

}

impl<'a> From<&'a [&'a str]> for ObjectIndexes<'a, 0> {

    fn from(keys: &'a [&'a str]) -> Self {
        Self {
            inner: Inner::Slice(keys),
        }
    }

}