From b8f7487e540a931862b8172b7184aee14d43b510 Mon Sep 17 00:00:00 2001 From: Deirdre Connolly Date: Mon, 10 Feb 2020 16:50:51 -0500 Subject: [PATCH] Use AsRef<[u8]>> in From impl --- zebra-chain/src/note_encryption.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/zebra-chain/src/note_encryption.rs b/zebra-chain/src/note_encryption.rs index a3662095c..9b157dff5 100644 --- a/zebra-chain/src/note_encryption.rs +++ b/zebra-chain/src/note_encryption.rs @@ -1,6 +1,9 @@ //! Note encryption types. -use std::{convert::From, fmt}; +use std::{ + convert::{AsRef, From}, + fmt, +}; /// A 512-byte _Memo_ field associated with a note, as described in /// [protocol specification ยง5.5][ps]. @@ -12,9 +15,9 @@ use std::{convert::From, fmt}; #[derive(Clone, Copy)] pub struct Memo([u8; 512]); -impl From for Memo { - fn from(input: String) -> Self { - let input_bytes = input.as_bytes(); +impl> From for Memo { + fn from(input: T) -> Self { + let input_bytes: &[u8] = input.as_ref(); let mut full_bytes = [0; 512]; @@ -75,7 +78,7 @@ fn memo_fmt() { #[test] fn memo_from_string() { - let memo = Memo::from("foo bar baz".to_string()); + let memo = Memo::from("foo bar baz"); println!("{:?}", memo); }