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

Namaste

Copyright (C) 2019, 2021-2023  Anonymous

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

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 |              | [Mutex objects][win:mutex-objects]
//!
//! Other systems are not supported.
//!
//! [Semantic Versioning 2.0.0]: https://semver.org/spec/v2.0.0.html
//! [win:mutex-objects]: https://docs.microsoft.com/en-us/windows/win32/sync/mutex-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
#![cfg_attr(any(target_os = "linux", target_os = "l4re", target_os = "android"), feature(unix_socket_abstract), feature(tcp_quickack))]
#![cfg_attr(target_family = "unix", feature(unix_socket_ancillary_data))]

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

macro_rules! code_name  { () => { "namaste" }}
macro_rules! version    { () => { "0.22.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) = (2023, 2, 10);

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

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

/// # 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, __!()) };
}

macro_rules! plural_s { ($n: expr) => { if $n == 1 { concat!() } else { concat!('s') }}}

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

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

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

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

#[cfg(unix)]
mod udsx_unix_stream;

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

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

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

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

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

#[cfg(windows)]
mod windows;

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

// ╔═════════╗
// ║   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"));
}
