comparison src/error.rs @ 24:1941e9d9819c

Fix unsound manipulation of env vars Modifying env vars in multi-threaded process is unsound but this crate was neither checking the number of threads nor mark its functions as `unsafe`. This change fixes it by both adding a check and adding an `unsafe` function that can bypass that check if needed.
author Martin Habovstiak <martin.habovstiak@gmail.com>
date Fri, 28 Feb 2025 13:52:31 +0100
parents f6334887e3c8
children cfef4593e207
comparison
equal deleted inserted replaced
23:729392c49b46 24:1941e9d9819c
2 //! 2 //!
3 //! This module separates the error types from root module to avoid clutter. 3 //! This module separates the error types from root module to avoid clutter.
4 4
5 5
6 use thiserror::Error; 6 use thiserror::Error;
7 use std::fmt;
7 use std::io; 8 use std::io;
9
10 /// Error returned when the library initialization fails.
11 #[derive(Debug)]
12 pub struct InitError(pub(crate) InitErrorInner);
13
14 #[cfg(all(target_os = "linux", feature = "enable_systemd"))]
15 type InitErrorInner = super::systemd_sockets::InitError;
16
17 #[cfg(not(all(target_os = "linux", feature = "enable_systemd")))]
18 type InitErrorInner = std::convert::Infallible;
19
20 impl fmt::Display for InitError {
21 #[inline]
22 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23 fmt::Display::fmt(&self.0, f)
24 }
25 }
26
27 impl std::error::Error for InitError {
28 #[inline]
29 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
30 self.0.source()
31 }
32 }
8 33
9 /// Error that can occur during parsing of `SocketAddr` from a string 34 /// Error that can occur during parsing of `SocketAddr` from a string
10 /// 35 ///
11 /// This encapsulates possible errors that can occur when parsing the input. 36 /// This encapsulates possible errors that can occur when parsing the input.
12 /// It is currently opaque because the representation is not certain yet. 37 /// It is currently opaque because the representation is not certain yet.