Skip to content

[Rust] Add derive Copy Clone traits for decoders #940

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ static void generateEitherEnum(final Writer writer) throws IOException

static void generateReadBuf(final Appendable writer, final ByteOrder byteOrder) throws IOException
{
indent(writer, 0, "#[derive(Debug, Default)]\n");
indent(writer, 0, "#[derive(Clone, Copy, Debug, Default)]\n");
indent(writer, 0, "pub struct %s<%s> {\n", READ_BUF_TYPE, BUF_LIFETIME);
RustUtil.indent(writer, 1, "data: &%s [u8],\n", BUF_LIFETIME);
indent(writer, 0, "}\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,15 @@ void appendMessageHeaderDecoderFn(final Appendable out) throws IOException

void appendMessageStruct(final Appendable out, final String structName) throws IOException
{
indent(out, 1, "#[derive(Debug, Default)]\n");
if (this.codecType == Decoder)
{
indent(out, 1, "#[derive(Clone, Copy, Debug, Default)]\n");
}
else
{
indent(out, 1, "#[derive(Debug, Default)]\n");
}

indent(out, 1, "pub struct %s {\n", withLifetime(structName));
indent(out, 2, "buf: %s,\n", withLifetime(this.codecType.bufType()));
indent(out, 2, "initial_offset: usize,\n");
Expand Down