pub struct ProcStack {
pub pid: AtomicUsize,
/* private fields */
}Expand description
Stack abstraction for lightweight processes
§Example
use lightproc::proc_stack::ProcStack;
use lightproc::proc_state::EmptyProcState;
ProcStack::default()
.with_before_start(|s: &mut EmptyProcState| { println!("Before start"); })
.with_after_complete(|s: &mut EmptyProcState| { println!("After complete"); })
.with_after_panic(|s: &mut EmptyProcState| { println!("After panic"); });Fields§
§pid: AtomicUsizeProcess ID for the Lightweight Process
Can be used to identify specific processes during any executor, reactor implementations.
Implementations§
Source§impl ProcStack
impl ProcStack
Sourcepub fn with_pid(self, pid: usize) -> ProcStack
pub fn with_pid(self, pid: usize) -> ProcStack
Adds pid for the process which is going to take this stack
§Example
use lightproc::proc_stack::ProcStack;
ProcStack::default()
.with_pid(1);Sourcepub fn with_state<S>(self, state: S) -> ProcStackwhere
S: State + 'static,
pub fn with_state<S>(self, state: S) -> ProcStackwhere
S: State + 'static,
Adds state for the process which is going to be embedded into this stack.
§Example
use lightproc::proc_stack::ProcStack;
pub struct GlobalState {
pub amount: usize
}
ProcStack::default()
.with_pid(1)
.with_state(GlobalState { amount: 1 });Sourcepub fn with_before_start<C, S>(self, callback: C) -> ProcStack
pub fn with_before_start<C, S>(self, callback: C) -> ProcStack
Adds a callback that will be executed before polling inner future to the stack
use lightproc::proc_stack::{ProcStack};
use lightproc::proc_state::EmptyProcState;
ProcStack::default()
.with_before_start(|s: &mut EmptyProcState| { println!("Before start"); });Sourcepub fn with_after_complete<C, S>(self, callback: C) -> ProcStack
pub fn with_after_complete<C, S>(self, callback: C) -> ProcStack
Adds a callback that will be executed after inner future resolves to an output to the stack
use lightproc::proc_stack::ProcStack;
use lightproc::proc_state::EmptyProcState;
ProcStack::default()
.with_after_complete(|s: &mut EmptyProcState| { println!("After complete"); });Sourcepub fn with_after_panic<C, S>(self, callback: C) -> ProcStack
pub fn with_after_panic<C, S>(self, callback: C) -> ProcStack
Adds a callback that will be executed after inner future panics to the stack
use lightproc::proc_stack::ProcStack;
use lightproc::proc_state::EmptyProcState;
ProcStack::default()
.with_after_panic(|s: &mut EmptyProcState| { println!("After panic"); });Sourcepub fn get_pid(&self) -> usize
pub fn get_pid(&self) -> usize
Utility function to get_pid for the implementation of executors.
use lightproc::proc_stack::ProcStack;
let proc = ProcStack::default().with_pid(123);
assert_eq!(proc.get_pid(), 123);Sourcepub fn get_state<S>(&self) -> S
pub fn get_state<S>(&self) -> S
Get the state which is embedded into this ProcStack.
use lightproc::proc_stack::ProcStack;
#[derive(Copy, Clone)]
pub struct GlobalState {
pub amount: usize
}
let mut proc = ProcStack::default().with_pid(123)
.with_state(GlobalState { amount: 0} );
let state = proc.get_state::<GlobalState>();Trait Implementations§
Auto Trait Implementations§
impl !Freeze for ProcStack
impl !RefUnwindSafe for ProcStack
impl Send for ProcStack
impl Sync for ProcStack
impl Unpin for ProcStack
impl !UnwindSafe for ProcStack
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<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 more