Struct racetime::handler::RaceContext
source · pub struct RaceContext<S: Send + Sync + ?Sized + 'static> {
pub global_state: Arc<S>,
/* private fields */
}
Expand description
A type passed to RaceHandler
callback methods which can be used to check the current status of the race or send messages.
While a future returned from a callback method is running, data
will not change and no other callbacks will be processed.
Clone
can be used to keep a value of this type past the end of a handler callback, e.g. by passing it into tokio::spawn
.
If you do so, data
can be called to check the current state of the race.
Fields§
§global_state: Arc<S>
Implementations§
source§impl<S: Send + Sync + ?Sized + 'static> RaceContext<S>
impl<S: Send + Sync + ?Sized + 'static> RaceContext<S>
sourcepub async fn data(&self) -> RwLockReadGuard<'_, RaceData>
pub async fn data(&self) -> RwLockReadGuard<'_, RaceData>
Returns the current state of the race.
See the type-level documentation for the semantics of using a RaceContext
for an extended period of time.
sourcepub async fn say(&self, message: &str) -> Result<(), Error>
pub async fn say(&self, message: &str) -> Result<(), Error>
Send a simple chat message to the race room.
See send_message
for more options.
sourcepub async fn send_message(
&self,
message: &str,
pinned: bool,
actions: Vec<(&str, ActionButton)>
) -> Result<(), Error>
pub async fn send_message( &self, message: &str, pinned: bool, actions: Vec<(&str, ActionButton)> ) -> Result<(), Error>
Send a chat message to the race room.
message
should be the message string you want to send.- If
pinned
is set to true, the sent message will be automatically pinned. - If
actions
is provided, action buttons will appear below your message for users to click on. See action buttons for more details.
sourcepub async fn send_direct_message(
&self,
message: &str,
direct_to: &str
) -> Result<(), Error>
pub async fn send_direct_message( &self, message: &str, direct_to: &str ) -> Result<(), Error>
Send a direct message only visible to its recipient.
message
should be the message string you want to send.direct_to
should be the hashid of the user.
sourcepub async fn pin_message(&self, message_id: &str) -> Result<(), Error>
pub async fn pin_message(&self, message_id: &str) -> Result<(), Error>
Pin a chat message.
message_id
should be the id
field of a ChatMessage
.
sourcepub async fn unpin_message(&self, message_id: &str) -> Result<(), Error>
pub async fn unpin_message(&self, message_id: &str) -> Result<(), Error>
Unpin a chat message.
message_id
should be the id
field of a ChatMessage
.
sourcepub async fn set_bot_raceinfo(&self, info: &str) -> Result<(), Error>
pub async fn set_bot_raceinfo(&self, info: &str) -> Result<(), Error>
Set the info_bot
field on the race room’s data.
sourcepub async fn set_user_raceinfo(
&self,
info: &str,
pos: RaceInfoPos
) -> Result<(), Error>
pub async fn set_user_raceinfo( &self, info: &str, pos: RaceInfoPos ) -> Result<(), Error>
Set the info_user
field on the race room’s data.
info
should be the information you wish to set, and pos
the behavior in case there is existing info.
sourcepub async fn set_invitational(&self) -> Result<(), Error>
pub async fn set_invitational(&self) -> Result<(), Error>
Set the room in an invite-only state.
sourcepub async fn force_start(&self) -> Result<(), Error>
pub async fn force_start(&self) -> Result<(), Error>
Forces a start of the race.
sourcepub async fn cancel_race(&self) -> Result<(), Error>
pub async fn cancel_race(&self) -> Result<(), Error>
Forcibly cancels a race.
sourcepub async fn invite_user(&self, user: &str) -> Result<(), Error>
pub async fn invite_user(&self, user: &str) -> Result<(), Error>
Invites a user to the race.
user
should be the hashid of the user.
sourcepub async fn accept_request(&self, user: &str) -> Result<(), Error>
pub async fn accept_request(&self, user: &str) -> Result<(), Error>
Accepts a request to join the race room.
user
should be the hashid of the user.
sourcepub async fn force_unready(&self, user: &str) -> Result<(), Error>
pub async fn force_unready(&self, user: &str) -> Result<(), Error>
Forcibly unreadies an entrant.
user
should be the hashid of the user.
sourcepub async fn remove_entrant(&self, user: &str) -> Result<(), Error>
pub async fn remove_entrant(&self, user: &str) -> Result<(), Error>
Forcibly removes an entrant from the race.
user
should be the hashid of the user.
Trait Implementations§
source§impl<S: Send + Sync + ?Sized + 'static> Clone for RaceContext<S>
impl<S: Send + Sync + ?Sized + 'static> Clone for RaceContext<S>
source§fn clone(&self) -> Self
fn clone(&self) -> Self
This is a cheap operation since this type is a wrapper around some Arc
s. See the type-level documentation for the semantics of using a RaceContext
for an extended period of time.
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreAuto Trait Implementations§
impl<S> Freeze for RaceContext<S>where
S: ?Sized,
impl<S> !RefUnwindSafe for RaceContext<S>
impl<S> Send for RaceContext<S>where
S: ?Sized,
impl<S> Sync for RaceContext<S>where
S: ?Sized,
impl<S> Unpin for RaceContext<S>where
S: ?Sized,
impl<S> !UnwindSafe for RaceContext<S>
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> 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