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