pub trait System<C: CustomTypes<Self>>: 'static + Sized {
type RequestKey: 'static + Key<Result<C::Intermediate, CompactString>>;
type CommandKey: 'static + Key<Result<(), CompactString>>;
// Required methods
fn rand<T: SampleUniform, R: SampleRange<T>>(&self, range: R) -> T;
fn time(&self, precision: Precision) -> SysTime;
fn perform_request<'gc>(
&self,
mc: &Mutation<'gc>,
request: Request<'gc, C, Self>,
proc: &mut Process<'gc, C, Self>,
) -> Result<Self::RequestKey, ErrorCause<C, Self>>;
fn poll_request<'gc>(
&self,
mc: &Mutation<'gc>,
key: &Self::RequestKey,
proc: &mut Process<'gc, C, Self>,
) -> Result<AsyncResult<Result<Value<'gc, C, Self>, CompactString>>, ErrorCause<C, Self>>;
fn perform_command<'gc>(
&self,
mc: &Mutation<'gc>,
command: Command<'gc, '_, C, Self>,
proc: &mut Process<'gc, C, Self>,
) -> Result<Self::CommandKey, ErrorCause<C, Self>>;
fn poll_command<'gc>(
&self,
mc: &Mutation<'gc>,
key: &Self::CommandKey,
proc: &mut Process<'gc, C, Self>,
) -> Result<AsyncResult<Result<(), CompactString>>, ErrorCause<C, Self>>;
fn send_message(
&self,
msg_type: CompactString,
values: VecMap<CompactString, Json, false>,
targets: Vec<CompactString>,
expect_reply: bool,
) -> Result<Option<ExternReplyKey>, ErrorCause<C, Self>>;
fn poll_reply(&self, key: &ExternReplyKey) -> AsyncResult<Option<Json>>;
fn send_reply(
&self,
key: InternReplyKey,
value: Json,
) -> Result<(), ErrorCause<C, Self>>;
fn receive_message(&self) -> Option<IncomingMessage>;
}
Expand description
Represents all the features of an implementing system.
This type encodes any features that cannot be performed without platform-specific resources.
When implementing System
for some type, you may prefer to not support one or more features.
This can be accomplished by returning the ErrorCause::NotSupported
variant for the relevant Feature
.
Required Associated Types§
Sourcetype RequestKey: 'static + Key<Result<C::Intermediate, CompactString>>
type RequestKey: 'static + Key<Result<C::Intermediate, CompactString>>
Key type used to await the result of an asynchronous request.
Sourcetype CommandKey: 'static + Key<Result<(), CompactString>>
type CommandKey: 'static + Key<Result<(), CompactString>>
Key type used to await the completion of an asynchronous command.
Required Methods§
Sourcefn rand<T: SampleUniform, R: SampleRange<T>>(&self, range: R) -> T
fn rand<T: SampleUniform, R: SampleRange<T>>(&self, range: R) -> T
Gets a random value sampled from the given range
, which is assumed to be non-empty.
The input for this generic function is such that it is compatible with rand::Rng::gen_range
,
which makes it possible to implement this function with any random provider under the rand
crate standard.
Sourcefn perform_request<'gc>(
&self,
mc: &Mutation<'gc>,
request: Request<'gc, C, Self>,
proc: &mut Process<'gc, C, Self>,
) -> Result<Self::RequestKey, ErrorCause<C, Self>>
fn perform_request<'gc>( &self, mc: &Mutation<'gc>, request: Request<'gc, C, Self>, proc: &mut Process<'gc, C, Self>, ) -> Result<Self::RequestKey, ErrorCause<C, Self>>
Performs a general request which returns a value to the system.
Ideally, this function should be non-blocking, and the requestor will await the result asynchronously.
The Entity
that made the request is provided for context.
Sourcefn poll_request<'gc>(
&self,
mc: &Mutation<'gc>,
key: &Self::RequestKey,
proc: &mut Process<'gc, C, Self>,
) -> Result<AsyncResult<Result<Value<'gc, C, Self>, CompactString>>, ErrorCause<C, Self>>
fn poll_request<'gc>( &self, mc: &Mutation<'gc>, key: &Self::RequestKey, proc: &mut Process<'gc, C, Self>, ) -> Result<AsyncResult<Result<Value<'gc, C, Self>, CompactString>>, ErrorCause<C, Self>>
Poll for the completion of an asynchronous request.
The Entity
that made the request is provided for context.
Sourcefn perform_command<'gc>(
&self,
mc: &Mutation<'gc>,
command: Command<'gc, '_, C, Self>,
proc: &mut Process<'gc, C, Self>,
) -> Result<Self::CommandKey, ErrorCause<C, Self>>
fn perform_command<'gc>( &self, mc: &Mutation<'gc>, command: Command<'gc, '_, C, Self>, proc: &mut Process<'gc, C, Self>, ) -> Result<Self::CommandKey, ErrorCause<C, Self>>
Performs a general command which does not return a value to the system.
Ideally, this function should be non-blocking, and the commander will await the task’s completion asynchronously.
The Entity
that issued the command is provided for context.
Sourcefn poll_command<'gc>(
&self,
mc: &Mutation<'gc>,
key: &Self::CommandKey,
proc: &mut Process<'gc, C, Self>,
) -> Result<AsyncResult<Result<(), CompactString>>, ErrorCause<C, Self>>
fn poll_command<'gc>( &self, mc: &Mutation<'gc>, key: &Self::CommandKey, proc: &mut Process<'gc, C, Self>, ) -> Result<AsyncResult<Result<(), CompactString>>, ErrorCause<C, Self>>
Poll for the completion of an asynchronous command.
The Entity
that issued the command is provided for context.
Sourcefn send_message(
&self,
msg_type: CompactString,
values: VecMap<CompactString, Json, false>,
targets: Vec<CompactString>,
expect_reply: bool,
) -> Result<Option<ExternReplyKey>, ErrorCause<C, Self>>
fn send_message( &self, msg_type: CompactString, values: VecMap<CompactString, Json, false>, targets: Vec<CompactString>, expect_reply: bool, ) -> Result<Option<ExternReplyKey>, ErrorCause<C, Self>>
Sends a message containing a set of named values
to each of the specified targets
.
The expect_reply
value controls whether or not to use a reply mechanism to asynchronously receive a response from the target(s).
In the case that there are multiple targets, only the first reply (if any) should be used.
Sourcefn poll_reply(&self, key: &ExternReplyKey) -> AsyncResult<Option<Json>>
fn poll_reply(&self, key: &ExternReplyKey) -> AsyncResult<Option<Json>>
Polls for a response from a client initiated by System::send_message
.
If the client responds, a value of [Some(x)
] is returned.
The system may elect to impose a timeout for reply results, in which case None
is returned instead.
Sourcefn send_reply(
&self,
key: InternReplyKey,
value: Json,
) -> Result<(), ErrorCause<C, Self>>
fn send_reply( &self, key: InternReplyKey, value: Json, ) -> Result<(), ErrorCause<C, Self>>
Sends a reply to the sender of a blocking message this client received.
Sourcefn receive_message(&self) -> Option<IncomingMessage>
fn receive_message(&self) -> Option<IncomingMessage>
Attempts to receive a message from the message buffer.
This operation is always non-blocking and returns None
if there are no messages in the buffer.
If a message is received, a tuple of form (msg_type, values, reply_key)
is returned.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.