[ 
https://issues.apache.org/jira/browse/AVRO-3331?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17485797#comment-17485797
 ] 

Thomas Schilling commented on AVRO-3331:
----------------------------------------

Your `try_from` doesn't compile for me:

{code}
use avro_rs::Decimal;
use std::convert::TryFrom;

fn main() {
    let d = Decimal::from(vec![1, 24]);
    println!("{:?}", d);

    let bytes = <Vec<u8>>::try_from(d);
    println!("{:?}", bytes);
}
{code}
 
With avro-rs 0.13 and rust 1.58.1 I get:
{code}
error[E0277]: the trait bound `Vec<u8>: From<avro_rs::Decimal>` is not satisfied
 --> src/main.rs:8:17
  |
8 |     let bytes = <Vec<u8>>::try_from(d);
  |                 ^^^^^^^^^^^^^^^^^^^ the trait `From<avro_rs::Decimal>` is 
not implemented for `Vec<u8>`
  |
  = help: the following implementations were found:
            <Vec<T, A> as From<Box<[T], A>>>
            <Vec<T, A> as From<VecDeque<T, A>>>
            <Vec<T> as From<&[T]>>
            <Vec<T> as From<&mut [T]>>
          and 6 others
  = note: required because of the requirements on the impl of `Into<Vec<u8>>` 
for `avro_rs::Decimal`
  = note: required because of the requirements on the impl of 
`TryFrom<avro_rs::Decimal>` for `Vec<u8>`

error[E0277]: the trait bound `Vec<u8>: From<avro_rs::Decimal>` is not satisfied
 --> src/main.rs:8:17
  |
8 |     let bytes = <Vec<u8>>::try_from(d);
  |                 ^^^^^^^^^^^^^^^^^^^^^^ the trait `From<avro_rs::Decimal>` 
is not implemented for `Vec<u8>`
  |
  = help: the following implementations were found:
            <Vec<T, A> as From<Box<[T], A>>>
            <Vec<T, A> as From<VecDeque<T, A>>>
            <Vec<T> as From<&[T]>>
            <Vec<T> as From<&mut [T]>>
          and 6 others
  = note: required because of the requirements on the impl of `Into<Vec<u8>>` 
for `avro_rs::Decimal`
  = note: required because of the requirements on the impl of 
`TryFrom<avro_rs::Decimal>` for `Vec<u8>`

For more information about this error, try `rustc --explain E0277`.
{code}

> Rust: Cannot extract Decimal value
> ----------------------------------
>
>                 Key: AVRO-3331
>                 URL: https://issues.apache.org/jira/browse/AVRO-3331
>             Project: Apache Avro
>          Issue Type: Bug
>          Components: rust
>            Reporter: Thomas Schilling
>            Assignee: Martin Tzvetanov Grigorov
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 40m
>  Remaining Estimate: 0h
>
> The [Decimal|https://docs.rs/avro-rs/latest/avro_rs/struct.Decimal.html] type 
> (as of 0.13) doesn't have any methods or trait implementations that allow 
> users to extract the value. The only workaround I could think of would be to 
> parse the output of the `Debug` implementation. But that's clearly very 
> inefficient and fragile.
> The (unreleased?) version 0.14 also seems to have the same issue 
> ([source|https://github.com/apache/avro/blob/master/lang/rust/src/decimal.rs]).
> It might just be enough to make the {{to_vec }}method public and specify how 
> to interpret the result vector.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to