sj/lib.rs
1/*
2==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--
3
4SJ
5
6Copyright (C) 2019-2025 Anonymous
7
8There are several releases over multiple years,
9they are listed as ranges, such as: "2019-2025".
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//! # Some JSON implementation
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 is an implementation of [JSON](https://www.json.org/).
37//! - Parsing from [Read][std::io/Read]: [`parse()`][fn:parse].
38//! - Generating to JSON string: [`Json`][enum:Json].
39//!
40//! ## Notes
41//!
42//! - Documentation is built with all features. Some of them are optional. If you see components from other crates, you can view source to see
43//! what features are required.
44//!
45//! - Nightly Rust is only required for building documentation.
46//!
47//! [Semantic Versioning 2.0.0]: https://semver.org/spec/v2.0.0.html
48//!
49//! [std::io/Read]: https://doc.rust-lang.org/std/io/trait.Read.html
50//!
51//! [fn:parse]: fn.parse.html
52//! [enum:Json]: enum.Json.html
53
54#![warn(missing_docs)]
55#![no_std]
56#![feature(doc_cfg)]
57
58// ╔═════════════════╗
59// ║ IDENTIFIERS ║
60// ╚═════════════════╝
61
62macro_rules! code_name { () => { "sj" }}
63macro_rules! version { () => { "2.0.3" }}
64
65/// # Crate name
66pub const NAME: &str = "SJ";
67
68/// # Crate code name
69pub const CODE_NAME: &str = code_name!();
70
71/// # ID of this crate
72pub const ID: &str = concat!(
73 "d1e51da8-8e4e9fc1-6d3f9d7e-c135be7d-a1cdeb80-6920a8dd-d18e7fc6-3e1d2013-",
74 "208af671-7371879e-1b7a8d84-2613ca10-dfeea565-302e82c4-53dd84e8-f31d9ead",
75);
76
77/// # Crate version
78pub const VERSION: &str = version!();
79
80/// # Crate release date (year/month/day)
81pub const RELEASE_DATE: (u16, u8, u8) = (2025, 3, 21);
82
83/// # Tag, which can be used for logging...
84pub const TAG: &str = concat!(code_name!(), "::d1e51da8::", version!());
85
86// ╔════════════════════╗
87// ║ IMPLEMENTATION ║
88// ╚════════════════════╝
89
90extern crate alloc;
91
92#[cfg(feature="std")]
93extern crate std;
94
95/// # Makes new Error
96macro_rules! e {
97 ($s: literal) => {
98 $crate::Error::new(line!(), module_path!(), Some(alloc::borrow::Cow::Borrowed($s)))
99 };
100}
101
102/// # Makes new Error
103macro_rules! err {
104 ($($arg: tt)*) => {
105 $crate::Error::new(line!(), module_path!(), Some(alloc::borrow::Cow::Owned(alloc::format!($($arg)*))))
106 };
107}
108
109#[test]
110fn test_macro_err() {
111 use alloc::borrow::Cow;
112
113 macro_rules! s_test { () => { "test" }}
114
115 fn eq(first: Error, second: Error) -> bool {
116 first.line() == second.line() && first.module_path() == second.module_path() && first.msg() == second.msg()
117 }
118
119 assert!(eq(err!("{s:?}", s=s_test!()), Error::new(line!(), module_path!(), Some(Cow::Owned(alloc::format!("{:?}", s_test!()))))));
120
121 let some = "===";
122 assert_eq!(err!("{some}").msg(), Error::new(line!(), module_path!(), Some(Cow::Borrowed(some))).msg());
123}
124
125mod bytes;
126mod error;
127mod json;
128mod map;
129mod map_kind;
130mod number;
131mod parser;
132
133pub use self::{
134 error::*,
135 json::*,
136 map::*,
137 map_kind::*,
138 number::*,
139};
140
141#[cfg(feature="std")]
142#[doc(cfg(feature="std"))]
143pub use self::parser::*;
144
145pub mod version_info;
146
147/// # Result type used in this crate
148pub type Result<T> = core::result::Result<T, Error>;
149
150/// # Result for I/O functions
151#[cfg(feature="std")]
152#[doc(cfg(feature="std"))]
153pub type IoResult<T> = core::result::Result<T, std::io::Error>;
154
155#[test]
156fn test_crate_version() {
157 assert_eq!(VERSION, env!("CARGO_PKG_VERSION"));
158}