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

R/O

Copyright (C) 2019, 2026  Anonymous



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/>.

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

//! # Read-only container

use core::{
    fmt::{self, Display, Formatter},
    ops::Deref,
};

/// # Read-only container
///
/// The key of this container is [`Deref`][core:Deref] implementation. It allows you to access public fields and immutable functions of `T`. In
/// case `T` has mutable functions, those are not accessible.
///
/// By design, the struct has no functions.
///
/// [core:Deref]: https://doc.rust-lang.org/core/ops/trait.Deref.html
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone)]
pub struct ReadOnly<T> {
    data: T,
}

impl<T> Deref for ReadOnly<T> {

    type Target = T;

    fn deref(&self) -> &Self::Target {
        &self.data
    }

}

impl<T> Display for ReadOnly<T> where T: Display {

    fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
        self.data.fmt(f)
    }

}

impl<T> From<T> for ReadOnly<T> {

    fn from(data: T) -> Self {
        new(data)
    }

}

/// # Makes new read-only version of some value
pub const fn new<T>(some: T) -> ReadOnly<T> {
    ReadOnly {
        data: some,
    }
}