[][src]Struct muoxi_staging::prelude::CmdSet

pub struct CmdSet {
    pub cmds: Vec<Box<dyn Command + Send>>,
}

Defines a common collection of commands

The current set up for this logic is that CmdSet is a vector of mutable references to trait objects meaning that all commands and their nature must be defined within the Command trait, defining other data associated with the struct of the Command is futile as the compiler will ambiguous to the actual object the trait is attached too. For example:

Example

This example is not tested
struct CmdLook
impl CmdLook{
    fn method(){
        println!("Hello from object specific method");
    }
}
impl Command for CmdLoop{
    fn name() -> str{
        "look"
    }
    ...
}

let cmdlook = CmdLook{other: 1};
let cmdset = cmdset![cmdlook];
let cmd = cmdset.get("look").unwrap();

cmd.name(); //valid because this method is defined in trait
cmd.method() // invalid! Method returns object specific method which is invisible.

The main take away from this, is that Commands should run and be defined all within the Trait, creating a unit struct is just to give the Command a name.

Fields

cmds: Vec<Box<dyn Command + Send>>

holds a list of valid commands in set

Methods

impl CmdSet[src]

pub fn new(cmds: Vec<Box<dyn Command + Send>>) -> Self[src]

create a new command set based on appropriate structs that implement Command Trait

pub fn get(&mut self, cmd_string: String) -> Option<&mut (dyn Command + Send)>[src]

check to see if command exists within CmdSet and returns the dyn Command that it matches with this is still fucking confusing

Trait Implementations

impl Debug for CmdSet[src]

Auto Trait Implementations

impl !RefUnwindSafe for CmdSet

impl Send for CmdSet

impl Sync for CmdSet

impl Unpin for CmdSet

impl !UnwindSafe for CmdSet

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> IntoSql for T

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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