Closed mmstick closed 8 years ago
You need to call your struct something other than Result because Result is this built-in type.
If you absolutely do not want to rename your struct, you need to change the signature to:
pub fn check_account(account: &str) -> ::std::result::Result<Status, Error> {
or:
use std::result::Result as StdResult;
pub fn check_account(account: &str) -> StdResult<Status, Error> {
Well that was simple, although the setup seems to give this error:
Checking mmstick
rustcyp: unable to decode response: invalid type: Map at line 1 column 2
[{"Title":"Battlefield Heroes","Name":"BattlefieldHeroes","Domain":"battlefieldheroes.com","BreachDate":"2011-06-26","AddedDate":"2014-01-23T13:10:29Z","PwnCount":530270,"Description":"In June 2011 as part of a final breached data dump, the hacker collective "LulzSec" <a href=\"http://www.rockpapershotgun.com/2011/06/26/lulzsec-over-release-battlefield-heroes-data\" target=\"_blank\">obtained and released over half a million usernames and passwords from the game Battlefield Heroes</a>. The passwords were stored as MD5 hashes with no salt and many were easily converted back to their plain text versions.","DataClasses":["Passwords","Usernames"],"IsVerified":true,"IsSensitive":false,"IsActive":true,"IsRetired":false,"LogoType":"svg"}]
It works if you do type Results = Vec<Result>
instead of your struct. There is no "result" key in the response from haveibeenpwned.com.
I'm having a predicament where the response that I am getting from a website is a list of anonymous values contained within a map, so I created a struct that contains the values of each element, and then created a struct to contain a vector of those elements. It seems that I'm not able to do this though because it then errors that the
Result
return value inpub fn check_account(account: &str) -> Result<Status, Error>
has the wrong number of type arguments. It expects 0, but finds 2, and there should be 2, which is confusing. What's the method of obtaining values from maps?Source Code