-
Notifications
You must be signed in to change notification settings - Fork 23
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
Idea: More Conversion #63
Comments
LGTM! TODOs
p.s. I'm sorry to said that these features won't be implemented soon, but they are on the TODO list, we will do them asap. |
Consider there is a
Since Rust MVP has already be stable. We can make pub struct FooArray_MVP<const N: usize>([Foo; N]); then we can implement this for impl<const N: usize> From<[Foo; N]> for FooArray_MVP<N> {
fn from(value: [Foo; N]) -> Self {
FooArray_MVP(value)
}
}
impl From<Foo> for FooOpt {
fn from(v: Foo) -> Self {
FooOpt::new_builder().set(Some(v)).build()
}
}
impl FromIterator<Foo> for FooVec {
fn from_iter<T: IntoIterator<Item = Foo>>(iter: T) -> Self {
let mut builder = FooVec::new_builder();
for v in iter {
builder = builder.push(v);
}
builder.build()
}
}
impl From<&[Foo]> for FooVec {
fn from(v: &[Foo]) -> Self {
let mut builder = FooVec::new_builder();
for v in v {
builder = builder.push(v.clone());
}
builder.build()
}
}
pub struct FooArray_MVP<const N: usize>([Foo; N]);
impl<const N: usize> From<[Foo; N]> for FooArray_MVP<N> {
fn from(value: [Foo; N]) -> Self {
FooArray_MVP(value)
}
}
impl TryFrom<&[Foo]> for FooArray {
type Error = molecule::error::VerificationError;
fn try_from(value: &[Foo]) -> Result<Self, Self::Error> {
let mut builder = FooArray::new_builder();
let mut value: &[Foo; FooArray::ITEM_COUNT] = value.try_into().map_err(|_| {
molecule::error::VerificationError::TotalSizeNotMatch(
"total size not match".to_string(),
FooArray::ITEM_COUNT,
value.len(),
)
})?;
builder.set(value.clone());
Ok(builder.build())
}
} |
It's unclear to me how |
Most are implemented in #80, except for:
|
On second thought, type inference won't work for |
There's a complication: |
Also implemented conversion for |
Many
Pack
/Unpack
/PackVec
functionalities can be integrated into molecule codegen using standard conversion traits:[u8; len]
may panic)WDYT?
The text was updated successfully, but these errors were encountered: