pub struct Signal {
pub kind: SignalKind,
pub scope: SignalScope,
pub source: Principal,
}Expand description
A control signal message.
Signals are used for immediate control operations like stopping or canceling work in progress.
§Permission Checking
The signal itself does not contain permission information. Permission is determined by:
- The runtime layer’s Session that sends the signal
- The
SignalScopebeing targeted - The policy configured in the EventBus
§Why No Default?
DO NOT implement Default for Signal.
A signal requires:
- A valid
SignalKind - A valid
SignalScope - A valid
Principal(who is sending)
There is no sensible default for any of these.
§Example
use orcs_event::{Signal, SignalKind};
use orcs_types::{Principal, ChannelId, PrincipalId, SignalScope};
let principal = Principal::User(PrincipalId::new());
let channel = ChannelId::new();
let signal = Signal::new(
SignalKind::Cancel,
SignalScope::Channel(channel),
principal,
);Fields§
§kind: SignalKindWhat type of signal.
scope: SignalScopeWhat scope is affected.
source: PrincipalWho is sending the signal.
Implementations§
Source§impl Signal
impl Signal
Sourcepub fn new(kind: SignalKind, scope: SignalScope, source: Principal) -> Signal
pub fn new(kind: SignalKind, scope: SignalScope, source: Principal) -> Signal
Sourcepub fn veto(source: Principal) -> Signal
pub fn veto(source: Principal) -> Signal
Creates a Veto (global stop) signal.
Requires elevated privilege to execute.
§Arguments
source- Who is sending the signal
§Example
use orcs_event::Signal;
use orcs_types::{Principal, PrincipalId};
let principal = Principal::User(PrincipalId::new());
let signal = Signal::veto(principal);
assert!(signal.is_veto());
assert!(signal.is_global());Sourcepub fn cancel(channel: ChannelId, source: Principal) -> Signal
pub fn cancel(channel: ChannelId, source: Principal) -> Signal
Creates a Cancel signal for a specific channel.
§Arguments
channel- The channel to cancelsource- Who is sending the signal
§Example
use orcs_event::Signal;
use orcs_types::{Principal, ChannelId, PrincipalId};
let principal = Principal::User(PrincipalId::new());
let channel = ChannelId::new();
let signal = Signal::cancel(channel, principal);
assert!(!signal.is_veto());
assert!(signal.affects_channel(channel));Sourcepub fn affects_channel(&self, channel: ChannelId) -> bool
pub fn affects_channel(&self, channel: ChannelId) -> bool
Returns true if this signal affects the given channel.
Global signals affect all channels.
Sourcepub fn pause(channel: ChannelId, source: Principal) -> Signal
pub fn pause(channel: ChannelId, source: Principal) -> Signal
Creates a Pause signal for a specific channel.
§Arguments
channel- The channel to pausesource- Who is sending the signal
Sourcepub fn resume(channel: ChannelId, source: Principal) -> Signal
pub fn resume(channel: ChannelId, source: Principal) -> Signal
Creates a Resume signal for a specific channel.
§Arguments
channel- The channel to resumesource- Who is sending the signal
Sourcepub fn steer(
channel: ChannelId,
message: impl Into<String>,
source: Principal,
) -> Signal
pub fn steer( channel: ChannelId, message: impl Into<String>, source: Principal, ) -> Signal
Creates a Steer signal for a specific channel.
§Arguments
channel- The channel to steermessage- Instruction for how to change directionsource- Who is sending the signal
Sourcepub fn approve(approval_id: impl Into<String>, source: Principal) -> Signal
pub fn approve(approval_id: impl Into<String>, source: Principal) -> Signal
Creates an Approve signal for a pending HIL request.
§Arguments
approval_id- ID of the approval request to approvesource- Who is sending the signal (typically Human)
Sourcepub fn reject(
approval_id: impl Into<String>,
reason: Option<String>,
source: Principal,
) -> Signal
pub fn reject( approval_id: impl Into<String>, reason: Option<String>, source: Principal, ) -> Signal
Creates a Reject signal for a pending HIL request.
§Arguments
approval_id- ID of the approval request to rejectreason- Optional reason for rejectionsource- Who is sending the signal (typically Human)
Sourcepub fn is_approve(&self) -> bool
pub fn is_approve(&self) -> bool
Returns true if this is an Approve signal.
Sourcepub fn is_hil_response(&self) -> bool
pub fn is_hil_response(&self) -> bool
Returns true if this is a HIL response signal (Approve, Reject, or Modify).
Sourcepub fn modify(
approval_id: impl Into<String>,
modified_payload: Value,
source: Principal,
) -> Signal
pub fn modify( approval_id: impl Into<String>, modified_payload: Value, source: Principal, ) -> Signal
Creates a Modify signal for a pending HIL request.
Approves the request but with modified parameters.
§Arguments
approval_id- ID of the approval request to modifymodified_payload- Modified payload to use instead of originalsource- Who is sending the signal (typically Human)
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Signal
impl<'de> Deserialize<'de> for Signal
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Signal, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Signal, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Serialize for Signal
impl Serialize for Signal
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Auto Trait Implementations§
impl Freeze for Signal
impl RefUnwindSafe for Signal
impl Send for Signal
impl Sync for Signal
impl Unpin for Signal
impl UnsafeUnpin for Signal
impl UnwindSafe for Signal
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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> ⓘ
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> ⓘ
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