From a3bdddef70f640f22b500b27b214505aa4a175c8 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Mon, 16 May 2016 09:42:05 -0400 Subject: [PATCH] Accept generic AsRef<[u8]> as input --- src/lib.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index a172b95..ddd5ce0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -53,7 +53,7 @@ impl QrCode { /// /// let code = QrCode::new(b"Some data").unwrap(); /// - pub fn new(data: &[u8]) -> QrResult { + pub fn new>(data: D) -> QrResult { QrCode::with_error_correction_level(data, EcLevel::M) } @@ -66,8 +66,8 @@ impl QrCode { /// /// let code = QrCode::with_error_correction_level(b"Some data", EcLevel::H).unwrap(); /// - pub fn with_error_correction_level(data: &[u8], ec_level: EcLevel) -> QrResult { - let bits = try!(bits::encode_auto(data, ec_level)); + pub fn with_error_correction_level>(data: D, ec_level: EcLevel) -> QrResult { + let bits = try!(bits::encode_auto(data.as_ref(), ec_level)); QrCode::with_bits(bits, ec_level) } @@ -84,9 +84,9 @@ impl QrCode { /// /// let micro_code = QrCode::with_version(b"123", Version::Micro(1), EcLevel::L).unwrap(); /// - pub fn with_version(data: &[u8], version: Version, ec_level: EcLevel) -> QrResult { + pub fn with_version>(data: D, version: Version, ec_level: EcLevel) -> QrResult { let mut bits = bits::Bits::new(version); - try!(bits.push_optimal_data(data)); + try!(bits.push_optimal_data(data.as_ref())); try!(bits.push_terminator(ec_level)); QrCode::with_bits(bits, ec_level) }