pub struct ProcessId(/* private fields */);Expand description
Process ID newtype for type safety
Wraps a u32 process ID to provide type safety and prevent accidental misuse. This ensures PIDs are only used in appropriate contexts and makes the code more self-documenting.
§Examples
use torrust_tracker_deployer_lib::infrastructure::persistence::filesystem::process_id::ProcessId;
// Get current process ID
let pid = ProcessId::current();
// Create from raw value
let pid = ProcessId::from_raw(12345);
// Get raw value
let raw: u32 = pid.as_u32();
// Parse from string
let pid: ProcessId = "12345".parse().unwrap();Implementations§
Source§impl ProcessId
impl ProcessId
Sourcepub fn current() -> Self
pub fn current() -> Self
Get the current process ID
§Examples
use torrust_tracker_deployer_lib::infrastructure::persistence::filesystem::process_id::ProcessId;
let current = ProcessId::current();
assert!(current.is_alive());Sourcepub fn from_raw(pid: u32) -> Self
pub fn from_raw(pid: u32) -> Self
Create a ProcessId from a raw u32
§Examples
use torrust_tracker_deployer_lib::infrastructure::persistence::filesystem::process_id::ProcessId;
let pid = ProcessId::from_raw(12345);
assert_eq!(pid.as_u32(), 12345);Sourcepub fn as_u32(&self) -> u32
pub fn as_u32(&self) -> u32
Get the raw u32 value
§Examples
use torrust_tracker_deployer_lib::infrastructure::persistence::filesystem::process_id::ProcessId;
let pid = ProcessId::from_raw(12345);
assert_eq!(pid.as_u32(), 12345);Sourcepub fn is_alive(&self) -> bool
pub fn is_alive(&self) -> bool
Check if this process is currently alive
Uses platform-specific methods to check if the process exists.
§Examples
use torrust_tracker_deployer_lib::infrastructure::persistence::filesystem::process_id::ProcessId;
let current = ProcessId::current();
assert!(current.is_alive());
let fake_pid = ProcessId::from_raw(999_999);
assert!(!fake_pid.is_alive());Trait Implementations§
impl Copy for ProcessId
impl Eq for ProcessId
impl StructuralPartialEq for ProcessId
Auto Trait Implementations§
impl Freeze for ProcessId
impl RefUnwindSafe for ProcessId
impl Send for ProcessId
impl Sync for ProcessId
impl Unpin for ProcessId
impl UnsafeUnpin for ProcessId
impl UnwindSafe for ProcessId
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::RequestSource§impl<T> IntoResult<T> for T
impl<T> IntoResult<T> for T
type Err = !
fn into_result(self) -> Result<T, <T as IntoResult<T>>::Err>
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.