WIP: Case Insensitive Objects #38

Draft
modulatingforce wants to merge 0 commits from case-insensitive-objects into master

In various area of code, I'm constantly having to remember to add .to_lowercase() because there's a known implied equality with those types. For example BotModule(name1) and BotModule(name2) are exactly the same if name1 = "Hello" and name2 = "hello"

Better would be to implement PartialEq and Eq traits for basic objects

Below is an example that seems to work in a different branch at the moment for BotModule

// #[derive(Debug, PartialEq, Eq, Hash, Clone)]
#[derive(Debug, Hash, Clone)]
pub enum ModType {
    BotModule(String),
}

impl PartialEq for ModType {
    fn eq(&self, other: &Self) -> bool {
        let BotModule(name1) = self.clone();
        let BotModule(name2) = other.clone();
        name1.to_lowercase() == name2.to_lowercase()
    }
}
impl Eq for ModType {}

Plan of Action

  • Review Rudimentary types (enum / structs) that derive PartialEq and Eq AND involve a String used to evaluate equality
    • If Many, optionally Prioritize those that would benefit from case insensitive
    • implement PartialEq and Eq for the types identified to change
  • May want to consider adding a new type Chatter(String)
    • This will add more meaning to comparisons involving that string name
    • This may require refactoring in structure such as HashMap that is currently just using String but known to be chatter names
    • this new type should also involve the new implementations of PartialEq and Eq
  • Correct areas where we manually added to_lowercase()
  • Unit tests that tests for case insensitivity

Not a HIGH priority , but doing this will help remove the weight of needing to consider case sensitive names when code involves comparing for equality with these types (including in HashMap related methods)

  • Fun to learn : more coding with traits . Adding this to Rust Learning
  • Low Difficulty : Can likely be delegated to others
In various area of code, I'm constantly having to remember to add `.to_lowercase()` because there's a known implied equality with those types. For example `BotModule(name1)` and `BotModule(name2)` are exactly the same if name1 = "Hello" and name2 = "hello" Better would be to implement PartialEq and Eq traits for basic objects Below is an example that seems to work in a different branch at the moment for `BotModule` ```rust // #[derive(Debug, PartialEq, Eq, Hash, Clone)] #[derive(Debug, Hash, Clone)] pub enum ModType { BotModule(String), } impl PartialEq for ModType { fn eq(&self, other: &Self) -> bool { let BotModule(name1) = self.clone(); let BotModule(name2) = other.clone(); name1.to_lowercase() == name2.to_lowercase() } } impl Eq for ModType {} ``` --- # Plan of Action - [ ] Review Rudimentary types (enum / structs) that derive PartialEq and Eq AND involve a String used to evaluate equality - [ ] If Many, optionally Prioritize those that would benefit from case insensitive - [ ] implement PartialEq and Eq for the types identified to change - [ ] May want to consider adding a new type `Chatter(String)` - This will add more meaning to comparisons involving that string name - This *may* require refactoring in structure such as HashMap that is currently just using String but known to be chatter names - this new type should also involve the new implementations of PartialEq and Eq - [ ] Correct areas where we manually added `to_lowercase()` - [ ] Unit tests that tests for case insensitivity --- Not a HIGH priority , but doing this will help remove the weight of needing to consider case sensitive names when code involves comparing for equality with these types (including in HashMap related methods) - Fun to learn : more coding with traits . Adding this to Rust Learning - Low Difficulty : Can likely be delegated to others
modulatingforce added the
Kind/Enhancement
Priority
Low
labels 2024-03-22 08:57:06 -04:00
modulatingforce added this to the Rust Learning project 2024-03-22 08:57:06 -04:00
Author
Owner
Example Working implementation on playground https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=6b0211f56600adaab255424f8595ddaa
Author
Owner
Related trait documentation https://doc.rust-lang.org/std/cmp/trait.Eq.html
modulatingforce added the
Complexity
Intermediate
Bot_Code
Core
labels 2024-03-27 18:23:22 -04:00
modulatingforce modified the project from Rust Learning to Forcebot Prototype 1.0 Push 2024-03-27 18:47:26 -04:00
modulatingforce added the
Phase 1.0
Requirements > Review & Planning
label 2024-03-27 20:12:48 -04:00
modulatingforce added the
Ownership
Needs Owner > May Delegate
label 2024-03-31 09:55:32 -04:00
All checks were successful
ci/woodpecker/push/cargo-checks Pipeline was successful
ci/woodpecker/pr/cargo-checks Pipeline was successful
This pull request is marked as a work in progress.
This branch is out-of-date with the base branch
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin case-insensitive-objects:case-insensitive-objects
git checkout case-insensitive-objects
Sign in to join this conversation.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: modulatingforce/forcebot_rs#38
No description provided.