Skip to main content

PreThreadAttestation

Struct PreThreadAttestation 

Source
pub struct PreThreadAttestation { /* private fields */ }
Expand description

Attests that the process is single-threaded at construction time.

UdsListener::bind calls umask(2), which is process-wide; any thread creating filesystem objects during the bind window would inherit the restricted umask. Holding a &PreThreadAttestation encodes the single-threaded precondition in the type signature so the invariant is enforced at compile time, not just by convention.

Construct exactly once at the top of fn main, before any thread spawn:

let pre_thread = PreThreadAttestation::new()?;
// … then pass &pre_thread to Observer::bind / UdsListener::bind

The token is !Send + !Sync (via PhantomData<*const ()>) so it cannot be moved into or shared across thread boundaries after construction.

Implementations§

Source§

impl PreThreadAttestation

Source

pub fn new() -> Result<Self>

Probe the OS thread count and return a token if the process is single-threaded.

On Linux counts /proc/self/task/ entries. On macOS calls pthread_is_threaded_np(3). On other platforms the runtime probe is skipped; the type-level structural guarantee still holds.

§Errors

Returns io::ErrorKind::Other if the process has more than one thread, or if the Linux /proc/self/task directory is unreadable.

Source

pub unsafe fn new_unchecked() -> Self

Create a token without a runtime probe.

Intended for test code where the multi-threaded test runner would incorrectly fail the probe even though the umask window is benign.

§Safety

The caller must ensure that no concurrent thread creates filesystem objects during the UdsListener::bind window, or that any such race is acceptable in the calling context.

Trait Implementations§

Source§

impl Debug for PreThreadAttestation

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.