Issue looking up value in HashMap<string,svc> by string converted from &[u8]

Hi!

Hobbyist here- I know I'll probably need to post some code, but am at work and hoping the issue is something obvious(it seems like it could beone of those)-

So I have a multi threaded server that is using a combination of unix sockets and channels to communicate-
-a thread grabs some input from the user in the console

  • sends it to the main thread (first via a channel and then via the socket)
  • input is used to look up the value by key.

HashMap is made like this

HashMap<"value.to_string()", svc>


//Bytes looked up like this

    Let a= String:from_utf8<input.to_vec()>
     map.get(a);

The issue is even though the values match by println! and the key is definitely in there, I never get a match! I was thinking it could be something to do with whatever protection they have on the HashMap but am unsure.

Any help would be much appreciated!

Are you stripping off the newline?

https://doc.rust-lang.org/std/io/trait.BufRead.html#method.read_line

all bytes up to, and including, the delimiter (if found) will be appended to buf

1 Like

I am in fact stripping off the new line before the channel and Unix socket, obviously something isn't equal though

a must match the key exactly, it is not sufficient if the input data you use for the lookup only contains the key you are trying to access.

It might be helpful to print a using String's Debug implementation to see if it really matches the desired key as Debug formatting escapes special characters.

3 Likes

If you can't access the hashmap you'll get a compiler error. There is no additional protection.

Thanks for clearing that one up for me!

Thanks for the response! I am stripping off new lines in the console but I see that it's possible the buffwriter or reader could be re adding them (hopefully)! I was so tired last night I totally forgot about debug it's been so long since I had to use it!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.