Simplified Rust code to use += operator instead of String.push_str().
This commit is contained in:
parent
390198ea4b
commit
ede63e8538
|
@ -238,13 +238,13 @@ impl QrCode {
|
||||||
pub fn to_svg_string(&self, border: i32) -> String {
|
pub fn to_svg_string(&self, border: i32) -> String {
|
||||||
assert!(border >= 0, "Border must be non-negative");
|
assert!(border >= 0, "Border must be non-negative");
|
||||||
let mut result: String = String::new();
|
let mut result: String = String::new();
|
||||||
result.push_str("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
|
result += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
|
||||||
result.push_str("<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n");
|
result += "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n";
|
||||||
let dimension = self.size.checked_add(border.checked_mul(2).unwrap()).unwrap();
|
let dimension = self.size.checked_add(border.checked_mul(2).unwrap()).unwrap();
|
||||||
result.push_str(&format!(
|
result += &format!(
|
||||||
"<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" viewBox=\"0 0 {0} {0}\" stroke=\"none\">\n", dimension));
|
"<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" viewBox=\"0 0 {0} {0}\" stroke=\"none\">\n", dimension);
|
||||||
result.push_str("\t<rect width=\"100%\" height=\"100%\" fill=\"#FFFFFF\"/>\n");
|
result += "\t<rect width=\"100%\" height=\"100%\" fill=\"#FFFFFF\"/>\n";
|
||||||
result.push_str("\t<path d=\"");
|
result += "\t<path d=\"";
|
||||||
let mut head: bool = true;
|
let mut head: bool = true;
|
||||||
for y in -border .. self.size + border {
|
for y in -border .. self.size + border {
|
||||||
for x in -border .. self.size + border {
|
for x in -border .. self.size + border {
|
||||||
|
@ -252,14 +252,14 @@ impl QrCode {
|
||||||
if head {
|
if head {
|
||||||
head = false;
|
head = false;
|
||||||
} else {
|
} else {
|
||||||
result.push_str(" ");
|
result += " ";
|
||||||
}
|
}
|
||||||
result.push_str(&format!("M{},{}h1v1h-1z", x + border, y + border));
|
result += &format!("M{},{}h1v1h-1z", x + border, y + border);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result.push_str("\" fill=\"#000000\"/>\n");
|
result += "\" fill=\"#000000\"/>\n";
|
||||||
result.push_str("</svg>\n");
|
result += "</svg>\n";
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue