Dictionary Implementation and Usage Guide
Overview
This repository provides a simple dictionary implementation in Rust with various functions to manipulate and interact with the dictionary data structure. The dictionary allows you to store key-value pairs where keys are of type String and values can be of any type T.
Functions and Usage
Include in project
use Dictionary;
new(o:bool) -> Self
This function creates a new instance of the Dictionary struct. The boolean paramater is a new and expiremental feature that adds the possibility to toggle of uniqueness. As it's not fully implemented, I suggest keeping it as true for now.
let mut my_dict = new;
push(&mut self, key: String, value: T) -> Result<(), String>
Use this function to add a new key-value pair to the dictionary. If the key already exists, it returns an error message.
let key = "name".to_string;
let value = "John".to_string;
match my_dict.push
pop(&mut self)
This function removes the newest (last-added) key-value pair from the dictionary.
my_dict.pop;
search(&self, key: String) -> bool
Use this function to check if a key exists in the dictionary.
if my_dict.search else
len(&self) -> usize
This function returns the number of key-value pairs in the dictionary.
let num_entries = my_dict.len;
println!;
drop(&mut self, key: String) -> bool
This function deletes a key-value pair based on the provided key. It returns true if the key-value pair was found and deleted, otherwise false.
if my_dict.drop else
contains(&self, value: &T) -> bool
This function checks if a given value exists in the dictionary's values.
if my_dict.contains else
###index_of(&self,key: String) -> Result<Vec, String> Searches and returns all indexes of a key
let key = "search_key";
match obj.index_of
overwrite(&mut self, key: String, newvalue: T) -> Result<(), String>
This function overwrites the value associated with a key. If the key is found, the value is updated. If the key is not found, an error is returned. Not update for unique = false yet.
match my_dict.overwrite
Example
use Dictionary;