Simple 1dim/multidim Array/Vec with Index:String OOP prefered

i'm new to Rust and i'm coming fresh from the high level coding (php,javascript and so on) and in my youth i have coded in pascal,c and c++. Now i my old ages;) i comes back to the systemcoding, back to the low level, and i miss the thousands helpers in high level;).

So my problem is. I read a simple config file with = sign to point for the value.


In my module i have a function thats reads the line and now i need a simple method to save the variables by runtime.

I want simple an array like this

let config_vars = [config_id_name[config_id_value]]
let config_vars = [config_id_name[config_id_value]]
let config_vars = [config_id_name[config_id_value]]

config_vars["Path"] = at this time fetched from config value;). Is that possible or can i really only index with usize?

Another way, the better why oop

struct Option

and with impl a construction that i can make this:

let cfg = Option ..... cfg["Path"] (so great if multidim;) cfg["Path"]["forthat"].config_value or so. like an object with an indexed array properties.

Yes i can name the object like the config_id but that sounds not right and are overdosed, i found.

let config_id_path = Config .... 

I hope this is easy possible, why it is an easy problem. Okay not for me at this time and in rust.

I suspect parts of your post have been lost due to incorrect formatting. Code examples should be between `backticks` for inline examples.

// Larger examples should be between fences.


I'm not entirely sure what you're trying to do or asking about. Your examples aren't clear (the "simple array" one is particularly confusing, because you appear to have duplicated the same line three times and I don't know why).

If you want simple configuration, I personally use serde + toml. This gives you a very easy way to write/read values to/from files.

As for indexing, you can only index arrays with usize. If you want to use something else as the key, look at BTreeMap and HashMap.

1 Like

Thx, perfectly this are my vars that i have searched. Its time for coding;). Before i use the great crates from the community i want to code every problem by myself to learn rust hard:).

As @DanielKeep said, a HashMap is probably what you're looking for. Check out the HashMap section of the Rust Programming Language book for an example that's similar to what you're doing :slight_smile: