From a54cadf25a3e5ca6742c594c34d632d7c4315423 Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Fri, 13 Apr 2018 18:33:05 +0000 Subject: [PATCH] Changed Rust code style to use Self for struct QrSegment. --- rust/src/lib.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 0f0678a..3f17db4 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -849,7 +849,7 @@ impl QrSegment { /*---- Static factory functions ----*/ // Returns a segment representing the given binary data encoded in byte mode. - pub fn make_bytes(data: &[u8]) -> QrSegment { + pub fn make_bytes(data: &[u8]) -> Self { let mut bb = BitBuffer(Vec::with_capacity(data.len() * 8)); for b in data { bb.append_bits(*b as u32, 8); @@ -860,7 +860,7 @@ impl QrSegment { // Returns a segment representing the given string of decimal digits encoded in numeric mode. // Panics if the string contains non-digit characters. - pub fn make_numeric(text: &[char]) -> QrSegment { + pub fn make_numeric(text: &[char]) -> Self { let mut bb = BitBuffer(Vec::with_capacity(text.len() * 3 + (text.len() + 2) / 3)); let mut accumdata: u32 = 0; let mut accumcount: u32 = 0; @@ -884,7 +884,7 @@ impl QrSegment { // Returns a segment representing the given text string encoded in alphanumeric mode. // The characters allowed are: 0 to 9, A to Z (uppercase only), space, dollar, percent, asterisk, // plus, hyphen, period, slash, colon. Panics if the string contains non-encodable characters. - pub fn make_alphanumeric(text: &[char]) -> QrSegment { + pub fn make_alphanumeric(text: &[char]) -> Self { let mut bb = BitBuffer(Vec::with_capacity(text.len() * 5 + (text.len() + 1) / 2)); let mut accumdata: u32 = 0; let mut accumcount: u32 = 0; @@ -910,7 +910,7 @@ impl QrSegment { // Returns a new mutable list of zero or more segments to represent the given Unicode text string. // The result may use various segment modes and switch modes to optimize the length of the bit stream. - pub fn make_segments(text: &[char]) -> Vec { + pub fn make_segments(text: &[char]) -> Vec { if text.is_empty() { vec![] } else if QrSegment::is_numeric(text) { @@ -926,7 +926,7 @@ impl QrSegment { // Returns a segment representing an Extended Channel Interpretation // (ECI) designator with the given assignment value. - pub fn make_eci(assignval: u32) -> QrSegment { + pub fn make_eci(assignval: u32) -> Self { let mut bb = BitBuffer(Vec::with_capacity(24)); if assignval < (1 << 7) { bb.append_bits(assignval, 8); @@ -944,8 +944,8 @@ impl QrSegment { // Creates a new QR Code data segment with the given parameters and data. - pub fn new(mode: QrSegmentMode, numchars: usize, data: Vec) -> QrSegment { - QrSegment { + pub fn new(mode: QrSegmentMode, numchars: usize, data: Vec) -> Self { + Self { mode: mode, numchars: numchars, data: data, @@ -976,7 +976,7 @@ impl QrSegment { /*---- Other static functions ----*/ // Package-private helper function. - fn get_total_bits(segs: &[QrSegment], version: Version) -> Option { + fn get_total_bits(segs: &[Self], version: Version) -> Option { let mut result: usize = 0; for seg in segs { let ccbits = seg.mode.num_char_count_bits(version);