gh_bofh_lib/lib.rs
1// SPDX-FileCopyrightText: 2024 - 2025 Ali Sajid Imami
2//
3// SPDX-License-Identifier: Apache-2.0
4// SPDX-License-Identifier: MIT
5
6//! This crate provides functionality to generate random BOFH (Bastard Operator
7//! From Hell) excuses.
8//!
9//! The purpose of this module is to allow an interface to generate random BOFH
10//! excuses. There are two _flavors_ of excuses: [classic](excuses::CLASSIC) and
11//! [modern](excuses::MODERN). Both flavors are available as static arrays of
12//! string slices.
13//!
14//! ## Classic excuses
15//! The classic excuses are inspired by the original BOFH excuse list from the
16//! 90s. They revolve around the problems around physcial hardware, network
17//! infrastructure and in-person enterprise support. There are a total of 467
18//! classic excuses in the list.
19//!
20//! You can see the list of classic excuses by importing the `CLASSIC` constant
21//! from [`gh_bofh_lib`](crate).
22//!
23//! You can also generate a random classic excuse by calling the
24//! [`random_classic`] function.
25//!
26//! ### Examples
27//! ```
28//! use gh_bofh_lib::random_classic;
29//! let excuse = random_classic();
30//! println!("{}", excuse);
31//! ```
32//!
33//! ## Modern excuses
34//!
35//! The modern excuses are inspired by the modern problems faced by IT
36//! professionals. They revolve around cloud infrastructure, software
37//! development, and remote support. There are a total of 105 modern excuses in
38//! the list.
39//!
40//! You can see the list of modern excuses by importing the `MODERN` constant
41//! from [`gh_bofh_lib`](crate).
42//!
43//! You can also generate a random modern excuse by calling the
44//! [`random_modern`] function.
45//!
46//! ### Examples
47//!
48//! ```
49//! use gh_bofh_lib::random_modern;
50//! let excuse = random_modern();
51//! println!("{}", excuse);
52//! ```
53//!
54//! ## Other Examples
55//!
56//! ```
57//! use gh_bofh_lib::{
58//! random_classic,
59//! random_modern,
60//! };
61//!
62//! let classic_excuse = random_classic();
63//! println!("Classic excuse: {}", classic_excuse);
64//!
65//! let modern_excuse = random_modern();
66//! println!("Modern excuse: {}", modern_excuse);
67//! ```
68
69pub mod excuses;
70
71pub use excuses::{
72 CLASSIC,
73 MODERN,
74};
75use rand::prelude::IndexedRandom;
76
77type ClassicExcuse = &'static str;
78type ModernExcuse = &'static str;
79
80/// Returns a random classic excuse
81///
82/// This function returns a random BOFH excuse from the classic list.
83///
84/// # Examples
85///
86/// ```
87/// use gh_bofh_lib::random_classic;
88///
89/// let excuse = random_classic();
90/// println!("{}", excuse);
91/// ```
92#[must_use]
93pub fn random_classic() -> ClassicExcuse {
94 CLASSIC
95 .choose(&mut rand::rng())
96 .unwrap_or(&"No excuse found, try again later")
97}
98
99/// Returns a random modern excuse
100///
101/// This function returns a random BOFH excuse from the modern list.
102///
103/// # Examples
104///
105/// ```
106/// use gh_bofh_lib::random_modern;
107///
108/// let excuse = random_modern();
109///
110/// println!("{}", excuse);
111/// ```
112#[must_use]
113pub fn random_modern() -> ModernExcuse {
114 MODERN
115 .choose(&mut rand::rng())
116 .unwrap_or(&"Excuse engine not initialized. Please try again later.")
117}
118
119#[cfg(test)]
120mod tests {
121 use super::*;
122
123 #[test]
124 fn test_random_classic() {
125 let excuse: ClassicExcuse = random_classic();
126 assert_ne!(excuse, "No excuse found, try again later");
127 }
128
129 #[test]
130 fn test_random_modern() {
131 let excuse: ModernExcuse = random_modern();
132 assert_ne!(
133 excuse,
134 "Excuse engine not initialized. Please try again later."
135 );
136 }
137}