dia_ip_range/
lib.rs

1/*
2==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--
3
4Dia-IP-Range
5
6Copyright (C) 2021-2024  Anonymous
7
8There are several releases over multiple years,
9they are listed as ranges, such as: "2021-2024".
10
11This program is free software: you can redistribute it and/or modify
12it under the terms of the GNU Lesser General Public License as published by
13the Free Software Foundation, either version 3 of the License, or
14(at your option) any later version.
15
16This program is distributed in the hope that it will be useful,
17but WITHOUT ANY WARRANTY; without even the implied warranty of
18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19GNU Lesser General Public License for more details.
20
21You should have received a copy of the GNU Lesser General Public License
22along with this program.  If not, see <https://www.gnu.org/licenses/>.
23
24::--::--::--::--::--::--::--::--::--::--::--::--::--::--::--::--
25*/
26
27//! # Dia IP range
28//!
29//! ## Project
30//!
31//! - License: GNU Lesser General Public License, either version 3, or (at your option) any later version.
32//! - _This project follows [Semantic Versioning 2.0.0]_
33//!
34//! ## Features
35//!
36//! This crate provides iterators for IPv4 addresses. This is useful for programs operating on local area networks (LANs).
37//!
38//! For examples, see [`IPv4RangeIter`][struct::IPv4RangeIter].
39//!
40//! ## Notes
41//!
42//! Documentation is built with all features. Some of them are optional. If you see some components from other crates, you can view source to
43//! see what features are required.
44//!
45//! [Semantic Versioning 2.0.0]: https://semver.org/spec/v2.0.0.html
46//!
47//! [struct::IPv4RangeIter]: struct.IPv4RangeIter.html
48
49#![warn(missing_docs)]
50#![no_std]
51#![deny(unsafe_code)]
52#![feature(doc_cfg)]
53
54// ╔═════════════════╗
55// ║   IDENTIFIERS   ║
56// ╚═════════════════╝
57
58macro_rules! code_name  { () => { "dia-ip-range" }}
59macro_rules! version    { () => { "0.10.0" }}
60
61/// # Crate name
62pub const NAME: &str = "Dia-IP-Range";
63
64/// # Crate code name
65pub const CODE_NAME: &str = code_name!();
66
67/// # ID of this crate
68pub const ID: &str = concat!(
69    "9b310d4b-54f515c0-112415bd-be4db60e-2e6fd1c8-919c250f-a92462fb-90297406-",
70    "06631349-7e828af7-f5928057-9c4a026c-51cc3702-02d14ce4-79cb109a-01ab7292",
71);
72
73/// # Crate version
74pub const VERSION: &str = version!();
75
76/// # Crate release date (year/month/day)
77pub const RELEASE_DATE: (u16, u8, u8) = (2024, 4, 11);
78
79/// # Tag, which can be used for logging...
80pub const TAG: &str = concat!(code_name!(), "::9b310d4b::", version!());
81
82// ╔════════════════════╗
83// ║   IMPLEMENTATION   ║
84// ╚════════════════════╝
85
86extern crate alloc;
87
88#[cfg(any(feature="iter", feature="std"))]
89extern crate std;
90
91/// # Makes new Error with formatted string, or without one
92macro_rules! err {
93    () => {
94        $crate::Error::new(line!(), module_path!(), None)
95    };
96    ($s: literal) => {
97        $crate::Error::new(line!(), module_path!(), Some(alloc::borrow::Cow::Borrowed($s)))
98    };
99    ($s: literal, $($arg: tt)+) => {
100        $crate::Error::new(line!(), module_path!(), Some(alloc::borrow::Cow::Owned(alloc::format!($s, $($arg)+))))
101    };
102}
103
104#[test]
105fn test_macro_err() {
106    use alloc::borrow::Cow;
107
108    macro_rules! s_test { () => { "test" }}
109
110    fn eq(first: Error, second: Error) -> bool {
111        first.line() == second.line() && first.module_path() == second.module_path() && first.msg() == second.msg()
112    }
113
114    assert!(eq(err!(), Error::new(line!(), module_path!(), None)));
115    assert!(eq(err!("test"), Error::new(line!(), module_path!(), Some(Cow::Borrowed(s_test!())))));
116    assert!(eq(err!("{s:?}", s=s_test!()), Error::new(line!(), module_path!(), Some(Cow::Owned(alloc::format!("{:?}", s_test!()))))));
117}
118
119mod error;
120mod ip_v4_component_range;
121mod ip_v4_range;
122
123pub mod debts;
124pub mod version_info;
125
126pub use self::{
127    error::*,
128    ip_v4_component_range::*,
129    ip_v4_range::*,
130};
131
132/// # Result type used in this crate
133pub type Result<T> = core::result::Result<T, Error>;
134
135#[test]
136fn test_crate_version() {
137    assert_eq!(VERSION, env!("CARGO_PKG_VERSION"));
138}