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

Namaste

Copyright (C) 2019, 2021-2025  Anonymous

There are several releases over multiple years,
they are listed as ranges, such as: "2021-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/>.

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

//! # Namaste
//!
//! ## Project
//!
//! - License: GNU Lesser General Public License, either version 3, or (at your option) any later version.
//! - _This project follows [Semantic Versioning 2.0.0]_
//!
//! ## Features
//!
//! - Handling locks amongst processes.
//! - Some [extensions][trait:UdsxUnixStream] for Unix domain sockets.
//!
//! ## Locks
//!
//! ### Usage
//!
//! An identifier is a non-empty byte array. Up to 64 bytes are supported. So, for example, you can use SHA3-512 hashes as IDs.
//!
//! You can call [`make()`][fn:make] or [`make_wait()`][fn:make_wait] to lock your IDs. When done, simply drop them via `drop()`.
//!
//! ### Notes
//!
//! | System  | Requirements | Implementation details
//! | ------- | ------------ | ----------------------
//! | Linux   | Nightly Rust | Abstract sockets (see `unix(7)`)
//! | Windows |              | [Event Objects][win:event-objects]
//!
//! Other systems are not supported.
//!
//! [Semantic Versioning 2.0.0]: https://semver.org/spec/v2.0.0.html
//! [win:event-objects]: https://learn.microsoft.com/en-us/windows/win32/sync/using-event-objects
//!
//! [fn:make]: fn.make.html
//! [fn:make_wait]: fn.make_wait.html
//! [trait:UdsxUnixStream]: trait.UdsxUnixStream.html

// TODO: remove these when related APIs are stabilized
#![feature(doc_cfg)]
#![cfg_attr(target_family="unix", feature(unix_socket_ancillary_data))]

// ╔═════════════════╗
// ║   IDENTIFIERS   ║
// ╚═════════════════╝

macro_rules! code_name  { () => { "namaste" }}
macro_rules! version    { () => { "0.30.0" }}

/// # Crate name
pub const NAME: &str = "Namaste";

/// # Crate code name
pub const CODE_NAME: &str = code_name!();

/// # ID of this crate
pub const ID: &str = concat!(
    "b1b4db58-59414682-a029819c-84b9a4e1-170e0050-92722253-fae9dfd6-b652a960-",
    "e553656c-6b625519-392bb87b-c23a6af3-c498c567-ff5c242f-606d2694-9113a891",
);

/// # Crate version
pub const VERSION: &str = version!();

/// # Crate release date (year/month/day)
pub const RELEASE_DATE: (u16, u8, u8) = (2025, 12, 26);

/// # Tag, which can be used for logging...
pub const TAG: &str = concat!(code_name!(), "::b1b4db58::", version!());

// ╔════════════════════╗
// ║   IMPLEMENTATION   ║
// ╚════════════════════╝

extern crate alloc;

/// # Wrapper for format!(), which prefixes your optional message with: crate::TAG, module_path!(), line!()
macro_rules! __ {
    ($($arg: tt)+) => {
        format!("[{tag}][{module_path}-{line}] {msg}", tag=crate::TAG, module_path=module_path!(), line=line!(), msg=format!($($arg)+))
    };
    () => {
        format!("[{tag}][{module_path}-{line}] (internal error)", tag=crate::TAG, module_path=module_path!(), line=line!())
    };
}

/// # Makes new std::io::Error
macro_rules! err {
    ($kind: path, $($arg: tt)+) => { std::io::Error::new($kind, __!($($arg)+)) };
    ($($arg: tt)+) => { err!(std::io::ErrorKind::Other, $($arg)+) };
    () => { std::io::Error::new(std::io::ErrorKind::Other, __!()) };
}

#[cfg(not(windows))]
macro_rules! plural_s { ($n: expr) => { if $n == 1 { concat!() } else { concat!('s') }}}

macro_rules! async_call { ($f: expr) => {{
    #[cfg(feature="tokio")]
    let r = $f.await;
    #[cfg(not(feature="tokio"))]
    let r = $f;
    r
}}}

macro_rules! sleep_duration { () => { 10 }}

pub mod debts;

// ╔═════════════════════╗
// ║   Linux & Windows   ║
// ╚═════════════════════╝

#[cfg(any(target_os="android", target_os="l4re", target_os="linux", windows))]
#[doc(cfg(any(target_os="android", target_os="l4re", target_os="linux", windows)))]
mod root;

#[cfg(any(target_os="android", target_os="l4re", target_os="linux", windows))]
#[doc(cfg(any(target_os="android", target_os="l4re", target_os="linux", windows)))]
pub use self::root::*;

// ╔══════════╗
// ║   Unix   ║
// ╚══════════╝

#[cfg(unix)]
#[doc(cfg(unix))]
mod udsx_unix_stream;

#[cfg(unix)]
#[doc(cfg(unix))]
pub use self::udsx_unix_stream::*;

// ╔═══════════╗
// ║   Linux   ║
// ╚═══════════╝

#[cfg(any(target_os="android", target_os="l4re", target_os="linux"))]
#[doc(cfg(any(target_os="android", target_os="l4re", target_os="linux")))]
mod linux;

#[cfg(any(target_os="android", target_os="l4re", target_os="linux"))]
#[doc(cfg(any(target_os="android", target_os="l4re", target_os="linux")))]
pub use self::linux::Namaste;

// ╔═════════════╗
// ║   Windows   ║
// ╚═════════════╝

#[cfg(windows)]
#[doc(cfg(windows))]
mod windows;

#[cfg(windows)]
#[doc(cfg(windows))]
pub use self::windows::Namaste;

// ╔═════════╗
// ║   All   ║
// ╚═════════╝

pub mod version_info;

/// # Result type used in this crate
pub type Result<T> = std::io::Result<T>;

#[test]
fn test_crate_version() {
    assert_eq!(VERSION, env!("CARGO_PKG_VERSION"));
}