Skip to content

Commit

Permalink
[Rust] Take slices by reference.
Browse files Browse the repository at this point in the history
  • Loading branch information
gierlachg committed Mar 11, 2024
1 parent c942cc6 commit 366ceb6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void generate() throws IOException
{
indent(libRs, 0, "#![forbid(unsafe_code)]\n");
indent(libRs, 0, "#![allow(clippy::upper_case_acronyms)]\n");
indent(libRs, 0, "#![allow(non_camel_case_types)]\n");
indent(libRs, 0, "#![allow(non_camel_case_types)]\n\n");
indent(libRs, 0, "use ::core::{convert::TryInto};\n\n");

final ArrayList<String> modules = new ArrayList<>();
Expand Down Expand Up @@ -226,7 +226,7 @@ static void generateWriteBuf(final Writer writer, final ByteOrder byteOrder) thr
indent(writer, 1, "#[inline]\n");
indent(writer, 1,
"pub fn put_bytes_at<const COUNT: usize>(&mut self, index: usize, bytes: [u8; COUNT]) -> usize {\n");
indent(writer, 2, "self.data[index..index + COUNT].copy_from_slice(&bytes);\n");
indent(writer, 2, "self.data[index..index + COUNT].copy_from_slice(bytes);\n");
indent(writer, 2, "COUNT\n");
indent(writer, 1, "}\n\n");

Expand All @@ -245,7 +245,7 @@ static void generateWriteBuf(final Writer writer, final ByteOrder byteOrder) thr
// put_<primitive>_at
indent(writer, 1, "#[inline]\n");
indent(writer, 1, "pub fn put_%1$s_at(&mut self, index: usize, value: %1$s) {\n", primitiveType);
indent(writer, 2, "self.put_bytes_at(index, %s::to_%s_bytes(value));\n", primitiveType, endianness);
indent(writer, 2, "self.put_bytes_at(index, &%s::to_%s_bytes(value));\n", primitiveType, endianness);
indent(writer, 1, "}\n\n");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ private static void generatePrimitiveEncoder(
indent(sb, level, "/// - encodedLength: %d\n", typeToken.encodedLength());
indent(sb, level, "/// - version: %d\n", typeToken.version());
indent(sb, level, "#[inline]\n");
indent(sb, level, "pub fn %s(&mut self, value: [%s; %d]) {\n",
indent(sb, level, "pub fn %s(&mut self, value: &[%s; %d]) {\n",
formatFunctionName(name),
rustPrimitiveType,
arrayLength);
Expand Down

0 comments on commit 366ceb6

Please sign in to comment.