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>

source

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.

source

pub async fn say(&self, message: &str) -> Result<(), Error>

Send a simple chat message to the race room.

See send_message for more options.

source

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.
source

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.
source

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.

source

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.

source

pub async fn set_bot_raceinfo(&self, info: &str) -> Result<(), Error>

Set the info_bot field on the race room’s data.

source

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.

source

pub async fn set_open(&self) -> Result<(), Error>

Set the room in an open state.

source

pub async fn set_invitational(&self) -> Result<(), Error>

Set the room in an invite-only state.

source

pub async fn force_start(&self) -> Result<(), Error>

Forces a start of the race.

source

pub async fn cancel_race(&self) -> Result<(), Error>

Forcibly cancels a race.

source

pub async fn invite_user(&self, user: &str) -> Result<(), Error>

Invites a user to the race.

user should be the hashid of the user.

source

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.

source

pub async fn force_unready(&self, user: &str) -> Result<(), Error>

Forcibly unreadies an entrant.

user should be the hashid of the user.

source

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.

source

pub async fn add_monitor(&self, user: &str) -> Result<(), Error>

Adds a user as a race monitor.

user should be the hashid of the user.

source

pub async fn remove_monitor(&self, user: &str) -> Result<(), Error>

Removes a user as a race monitor.

user should be the hashid of the user.

Trait Implementations§

source§

impl<S: Send + Sync + ?Sized + 'static> Clone for RaceContext<S>

source§

fn clone(&self) -> Self

This is a cheap operation since this type is a wrapper around some Arcs. 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)

Performs copy-assignment from source. Read more

Auto 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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more