diff options
| author | Fuwn <[email protected]> | 2021-05-01 23:34:55 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2021-05-01 23:34:55 +0000 |
| commit | cb58dab1828f847ffdf51e336c34bc71d973706d (patch) | |
| tree | 7f8bf76c58befda2b901d26ad4bc1980fa9e399f /src/server/cmd/extendable.rs | |
| parent | ci(actions): fix rust action not running on changes performed on the src dire... (diff) | |
| download | whirl-cb58dab1828f847ffdf51e336c34bc71d973706d.tar.xz whirl-cb58dab1828f847ffdf51e336c34bc71d973706d.zip | |
feat(cmds): trait based commands
This commit adds the abiltity to implement a series of given traits for a command, where each
command should implement **at least** one of these traits; Parsable, ParsableWithArguments,
Creatable. These changed are put in place to ensure that when implementing a command, the proper
methods are implemented in the proper format.
Diffstat (limited to 'src/server/cmd/extendable.rs')
| -rw-r--r-- | src/server/cmd/extendable.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/server/cmd/extendable.rs b/src/server/cmd/extendable.rs new file mode 100644 index 0000000..e6f3c2b --- /dev/null +++ b/src/server/cmd/extendable.rs @@ -0,0 +1,18 @@ +// Copyleft (ɔ) 2021-2021 The Whirlsplash Collective +// SPDX-License-Identifier: GPL-3.0-only + +pub trait Parsable { + fn parse(data: Vec<u8>) -> Self; +} + +pub trait Creatable { + fn create(self) -> Vec<u8>; +} + +/// Having to do this makes me with there was operator overloading in Rust. +/// +/// I *could* do this with a macro but since Text is the only struct that +/// implements this trait, it shouldn't be that big of a deal. +pub trait ParsableWithArguments { + fn parse(data: Vec<u8>, args: &[&str]) -> Self; +} |