Skip to main content

WalkDirection

Enum WalkDirection 

Source
pub enum WalkDirection {
    None,
    Forward,
    Backward,
    Left,
    Right,
    ForwardRight,
    ForwardLeft,
    BackwardRight,
    BackwardLeft,
}
Expand description

A direction that a player can walk in, including none.

Superset of SprintDirection.

This can be freely converted to and from DirectionStates.

Variants§

§

None

§

Forward

§

Backward

§

Left

§

Right

§

ForwardRight

§

ForwardLeft

§

BackwardRight

§

BackwardLeft

Implementations§

Source§

impl WalkDirection

Source

pub fn forward(self) -> bool

Returns true if the direction is forward, forward-right, or forward-left.

Source

pub fn backward(self) -> bool

Returns true if the direction is backward, backward-right, or backward-left.

Source

pub fn left(self) -> bool

Returns true if the direction is left, forward-left, or backward-left.

Source

pub fn right(self) -> bool

Returns true if the direction is right, forward-right, or backward-right.

Source

pub fn set_forward(&mut self, value: bool)

Source

pub fn set_backward(&mut self, value: bool)

Source

pub fn set_left(&mut self, value: bool)

Source

pub fn set_right(&mut self, value: bool)

Source

pub fn opposite(self) -> Self

Inverts the walk direction.

assert_eq!(WalkDirection::Forward.opposite(), WalkDirection::Backward);
assert_eq!(
    WalkDirection::BackwardRight.opposite(),
    WalkDirection::ForwardLeft
);
assert_eq!(WalkDirection::None.opposite(), WalkDirection::None);
Examples found in repository?
azalea/examples/testbot/commands/movement.rs (line 133)
127    fn walk_command(ctx: &Ctx, direction: WalkDirection) -> eyre::Result<i32> {
128        let mut seconds = get_float(ctx, "seconds").unwrap();
129        let source = ctx.source.lock();
130        let bot = source.bot.clone();
131
132        if seconds < 0. {
133            bot.walk(direction.opposite());
134            seconds = -seconds;
135        } else {
136            bot.walk(direction);
137        }
138
139        tokio::spawn(async move {
140            tokio::time::sleep(Duration::from_secs_f32(seconds)).await;
141            bot.walk(WalkDirection::None);
142        });
143        source.reply(format!("ok, walking {direction:?} for {seconds} seconds"));
144        Ok(1)
145    }

Trait Implementations§

Source§

impl Clone for WalkDirection

Source§

fn clone(&self) -> WalkDirection

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for WalkDirection

Source§

impl Debug for WalkDirection

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for WalkDirection

Source§

fn default() -> WalkDirection

Returns the “default value” for a type. Read more
Source§

impl Eq for WalkDirection

Source§

impl From<DirectionStates> for WalkDirection

Source§

fn from(d: DirectionStates) -> Self

Converts to this type from the input type.
Source§

impl From<SprintDirection> for WalkDirection

Source§

fn from(d: SprintDirection) -> Self

Converts to this type from the input type.
Source§

impl From<WalkDirection> for DirectionStates

Source§

fn from(d: WalkDirection) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for WalkDirection

Source§

fn eq(&self, other: &WalkDirection) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for WalkDirection

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> ConditionalSend for T
where T: Send,

§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSend for T
where T: Any + Send,

§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

impl<T> DynEq for T
where T: Any + Eq,

§

fn dyn_eq(&self, other: &(dyn DynEq + 'static)) -> bool

This method tests for self and other values to be equal. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromWorld for T
where T: Default,

§

fn from_world(_world: &mut World) -> T

Creates Self using default().

§

impl<T> Instrument for T

§

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

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

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.

§

impl<T> IntoResult<T> for T

§

fn into_result(self) -> Result<T, RunSystemError>

Converts this type into the system output type.
§

impl<A> Is for A
where A: Any,

§

fn is<T>() -> bool
where T: Any,

Checks if the current type “is” another type, using a TypeId equality comparison. This is most useful in the context of generic logic. Read more
§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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>,

Source§

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>,

Source§

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

impl<T> TypeData for T
where T: 'static + Send + Sync + Clone,

§

fn clone_type_data(&self) -> Box<dyn TypeData>

Creates a type-erased clone of this value.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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