lib.rs (1534B)
1 #![forbid(unsafe_code)] 2 #![cfg_attr(coverage_nightly, feature(coverage_attribute))] 3 4 use std::{error::Error, fmt}; 5 6 mod app; 7 mod core; 8 mod host_nostr; 9 #[cfg_attr(coverage_nightly, coverage(off))] 10 mod transport; 11 12 /// Stable, redacted failure returned by the daemon entry point. 13 pub struct RadrootsdRunError { 14 _private: (), 15 } 16 17 impl fmt::Debug for RadrootsdRunError { 18 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { 19 formatter.write_str("RadrootsdRunError") 20 } 21 } 22 23 impl fmt::Display for RadrootsdRunError { 24 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { 25 formatter.write_str("daemon execution failed") 26 } 27 } 28 29 impl Error for RadrootsdRunError {} 30 31 /// Runs the daemon without exposing implementation-owned modules or errors. 32 pub async fn run_daemon() -> Result<(), RadrootsdRunError> { 33 app::run() 34 .await 35 .map_err(|_source| RadrootsdRunError { _private: () }) 36 } 37 38 pub const fn crate_name() -> &'static str { 39 env!("CARGO_PKG_NAME") 40 } 41 42 #[cfg(test)] 43 #[cfg_attr(coverage_nightly, coverage(off))] 44 mod tests { 45 use std::error::Error; 46 47 #[test] 48 fn crate_name_matches_package() { 49 assert_eq!(super::crate_name(), "radrootsd"); 50 } 51 52 #[test] 53 fn run_error_is_source_free_and_redacted() { 54 let error = super::RadrootsdRunError { _private: () }; 55 assert_eq!(format!("{error}"), "daemon execution failed"); 56 assert_eq!(format!("{error:?}"), "RadrootsdRunError"); 57 assert!(error.source().is_none()); 58 } 59 }