Skip to content
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

feat: more conversion #80

Merged
merged 3 commits into from
Jan 4, 2024
Merged

Conversation

blckngm
Copy link

@blckngm blckngm commented Dec 28, 2023

Implement more conversion traits to make entities easier to build/use (close #63):

  • FooOpt from Foo
  • FooArray from/into [Foo; n]
  • FooArray TryFrom &[Foo]
  • Union entity from item
  • Vec FromIterator item
  • ByteArray from/into [u8; n]
  • ByteArray TryFrom &[u8]
  • ByteArrayReader Into &[u8; n]
  • ByteVec FromIterator u8

So instead of e.g.

.foo_opt(FooOpt::new_builder().set(Some(foo)).build())
.foo_vec(FooVec::new_builder().extend(foo_iter).build())
.foo_union(FooUnion::new_builder().set(foo).build())

we can use:

.foo_opt(foo.into())
.foo_vec(foo_iter.collect())
.foo_union(foo.into())

It's also easier to work with e.g. Uint32: 3u32.to_le_bytes().into(), u32::from_le_bytes(x.into()).

@blckngm blckngm mentioned this pull request Dec 28, 2023
@blckngm
Copy link
Author

blckngm commented Dec 29, 2023

@quake @yangby-cryptape Would you review this?

@quake
Copy link
Member

quake commented Dec 29, 2023

LGTM, there is an unit test CI error, @blckngm could you resolve it?

@blckngm
Copy link
Author

blckngm commented Dec 29, 2023

It's due to rust version used. Should be fixed now.

Copy link
Collaborator

@yangby-cryptape yangby-cryptape left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works well as it described.

@yangby-cryptape yangby-cryptape merged commit 3b277d8 into nervosnetwork:master Jan 4, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Idea: More Conversion
4 participants