#Convert Generic Array into String

1 messages · Page 1 of 1 (latest)

gentle schooner
#

I'm not sure how to do this conversion. I have it set up like this:

// check hash
let hash = Sha256::digest(res.text()?.as_bytes());
println!("HASH : {:?} vs {}",hash.iter().collect::<_>().to_string(),split[2]);
#

I originally tried this but its not working:

cloud totem
#

The generic for collect specifies the type which should be produced when collecting the iterator, assuming char was supposed to be the type of the items in the iterator...

gentle schooner
#

Ahh

#

so when its a ```rs
std::iter::Iterator<Item=&u8>

cloud totem
#

Do you want the items to be output as text?

gentle schooner
#

i need to compare it to a type String

#

hash == hash kinda deal

cloud totem
#

The result of a hash wouldn't necessarily be a valid string...?

gentle schooner
#

? its a sha256sum

cloud totem
#

Idk how that works.

gentle schooner
cloud totem
#

What's return type of digest?

gentle schooner
#
GenericArray<u8, UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>>
#

kinda cursed

cloud totem
#

I guess you could copy the items, and collect it into a Vec... then use String::from_utf8...

gentle schooner
#

how should i got about getting it into a vec?

cloud totem
#

You can use collect for that.