Help: How to write a struct implementation

I wrote a piece of code, but an error occurred

pub struct All<T> (T);

impl<T> All<T> {
    pub fn into(self) -> T {
        self.0
    }
}

impl<'r, T> FromRow<'r, MySqlRow> for All<T> {
    fn from_row(row: &'r MySqlRow) -> Result<Self, Error> {
        row.try_get(0).map(|i|All{ 0:  i})
    }
}

What is the correct way of writing? thanks

43  |         row.try_get(0).map(|i|All{ 0:  i})
    |             ^^^^^^^ the trait `sqlx::Decode<'_, MySql>` is not implemented for `T`

You probably need a trait bound on the T parameter:

// Untested
impl<'r, T> FromRow<'r, MySqlRow> for All<T>
where
    T: for<'a> Decode<'a, MySql> + Type<MySql>
{
    // ...
}

The full console output of cargo check probably has more information and perhaps suggestions. (It's also a good idea to include the full output here.)

1 Like

Thank you . The problem has been resolved。

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.