Last active
August 13, 2020 22:54
Revisions
-
olback revised this gist
Aug 13, 2020 . 1 changed file with 7 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -51,3 +51,10 @@ impl Foo { } } Foo::new(&vec); Foo::new(&slice); Foo::new(&[100, 183, 53, 126, 165, 0, 93, 255, 148, 76, 14, 247, 102, 240, 37, 255, 142, 53, 138, 255, 138, 163, 117, 138, 70, 182, 240, 249, 244, 107, 162, 151]); Foo::new(&"ZLc1fqUAXf+UTA73ZvAl/441iv+Ko3WKRrbw+fRropc="); Foo::new(&"ZLc1fqUAXf+UTA73ZvAl/441iv+Ko3WKRrbw+fRropc=".to_string()); Foo::new(&&"ZLc1fqUAXf+UTA73ZvAl/441iv+Ko3WKRrbw+fRropc=".to_string()); -
olback created this gist
Aug 13, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,53 @@ trait ToKey { fn to_key(&self) -> Vec<u8>; } impl ToKey for [u8; 32] { fn to_key(&self) -> Vec<u8> { (&self[..]).to_key() } } impl ToKey for &[u8] { fn to_key(&self) -> Vec<u8> { self.to_vec() } } impl ToKey for Vec<u8> { fn to_key(&self) -> Vec<u8> { self.clone() } } impl ToKey for &str { fn to_key(&self) -> Vec<u8> { base64::decode(&self).unwrap() } } impl ToKey for String { fn to_key(&self) -> Vec<u8> { (&**self).to_key() } } impl ToKey for &String { fn to_key(&self) -> Vec<u8> { (*self).to_key() } } struct Foo { bar: Vec<u8> } impl Foo { fn new(key: &dyn ToKey) -> Self { Self { bar: key.to_key() } } }