Skip to main content

Bindings

Struct Bindings 

Source
pub struct Bindings<T: BindingTypes> { /* private fields */ }
Expand description

Used for saving and loading input settings.

An action can either be a single button or a combination of them.

§Examples

Example Ron config file:

(
    axes: {
        "updown": Emulated(
            pos: Key(Up),
            neg: Key(Down)
        ),
        "leftright": Multiple([ // Multiple bindings for one axis
            Emulated(
                pos: Key(Right),
                neg: Key(Left)
            ),
            Emulated(
                pos: Key(D),
                neg: Key(A)
            )
        ])
    },
    actions: {
        "fire": [ [Mouse(Left)], [Key(X)] ], // Multiple bindings for one action
        "reload": [ [Key(LControl), Key(R)] ] // Combinations of multiple bindings possible
    }
)

Implementations§

Source§

impl<T: BindingTypes> Bindings<T>

Source

pub fn new() -> Self

Creates a new empty Bindings structure

Source§

impl<T: BindingTypes> Bindings<T>

Source

pub fn insert_axis<A: Into<T::Axis>>( &mut self, id: A, axis: Axis, ) -> Result<Option<Axis>, BindingError<T>>

Assign an axis to an ID value

This will insert a new axis if no entry for this id exists. If one does exist this will replace the axis at that id and return it.

Source

pub fn remove_axis<A>(&mut self, id: &A) -> Option<Axis>
where T::Axis: Borrow<A>, A: Hash + Eq + ?Sized,

Removes an axis, this will return the removed axis if successful.

Source

pub fn axis<A>(&self, id: &A) -> Option<&Axis>
where T::Axis: Borrow<A>, A: Hash + Eq + ?Sized,

Returns a reference to an axis.

Source

pub fn axes(&self) -> impl Iterator<Item = &T::Axis>

Gets a list of all axes

Source

pub fn insert_action_binding<B: IntoIterator<Item = Button>>( &mut self, id: T::Action, binding: B, ) -> Result<(), BindingError<T>>

Add a button or button combination to an action.

This will attempt to insert a new binding between this action and the button(s).

Source

pub fn remove_action_binding<A>( &mut self, id: &A, binding: &[Button], ) -> Result<(), ActionRemovedError>
where T::Action: Borrow<A>, A: Hash + Eq + ?Sized,

Removes an action binding that was assigned previously.

Source

pub fn action_bindings<A>(&self, id: &A) -> impl Iterator<Item = &[Button]>
where T::Action: Borrow<A>, A: Hash + Eq + ?Sized,

Returns an action’s bindings.

Source

pub fn actions(&self) -> impl Iterator<Item = &T::Action>

Gets a list of all action bindings

Source

pub fn check_invariants(&mut self) -> Result<(), BindingError<T>>

Check that this structure upholds its guarantees. Should only be necessary when serializing or deserializing the bindings.

Trait Implementations§

Source§

impl<T: BindingTypes> Clone for Bindings<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: BindingTypes> Debug for Bindings<T>

Source§

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

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

impl<T: BindingTypes> Default for Bindings<T>

Source§

fn default() -> Self

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

impl<'de, T: BindingTypes> Deserialize<'de> for Bindings<T>
where T::Axis: Deserialize<'de>, T::Action: Deserialize<'de>,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<T: BindingTypes> Serialize for Bindings<T>
where T::Axis: Serialize, T::Action: Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Bindings<T>

§

impl<T> RefUnwindSafe for Bindings<T>

§

impl<T> Send for Bindings<T>

§

impl<T> Sync for Bindings<T>

§

impl<T> Unpin for Bindings<T>
where <T as BindingTypes>::Axis: Unpin, <T as BindingTypes>::Action: Unpin,

§

impl<T> UnsafeUnpin for Bindings<T>

§

impl<T> UnwindSafe for Bindings<T>

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

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

impl<T> Config for T
where T: for<'a> Deserialize<'a> + Serialize,

Source§

fn load<P>(path: P) -> Result<T, ConfigError>
where P: AsRef<Path>,

Loads a configuration structure from a file.
Source§

fn load_bytes(bytes: &[u8]) -> Result<T, ConfigError>

Loads configuration structure from raw bytes.
Source§

fn write<P>(&self, path: P) -> Result<(), ConfigError>
where P: AsRef<Path>,

Writes a configuration structure to a file.
Source§

fn load_no_fallback<P>(path: P) -> Result<Self, ConfigError>
where P: AsRef<Path>,

👎Deprecated:

use load instead

Loads a configuration structure from a file.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> SetParameter for T

Source§

fn set<T>(&mut self, value: T) -> <T as Parameter<Self>>::Result
where T: Parameter<Self>,

Sets value as a parameter of self.
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

unsafe fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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> TryDefault for T
where T: Default,

Source§

fn try_default() -> Result<T, String>

Tries to create the default.
Source§

fn unwrap_default() -> Self

Calls try_default and panics on an error case.
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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

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

Source§

impl<T> Resource for T
where T: Any + Send + Sync,