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

Impl TryGetableMany for diffrent types of generices (A, B, C) #174

Closed
MuhannadAlrusayni opened this issue Sep 17, 2021 · 0 comments · Fixed by #175
Closed

Impl TryGetableMany for diffrent types of generices (A, B, C) #174

MuhannadAlrusayni opened this issue Sep 17, 2021 · 0 comments · Fixed by #175

Comments

@MuhannadAlrusayni
Copy link
Contributor

Hi, I find that I cannot use the type (i32, Uuid, i32) as PrimaryKeyTrait::ValueType.

I think this is because TryGetableMany is only implemented for tuples with the same type (e.g. (i32, i32, i32)).

Solving this should be easy:

// change this:
impl<T> TryGetableMany for (T, T)
where
    T: TryGetable,
{
    fn try_get_many(res: &QueryResult, pre: &str, cols: &[String]) -> Result<Self, TryGetError> {
        try_get_many_with_slice_len_of(2, cols)?;
        Ok((
            T::try_get(res, pre, &cols[0])?,
            T::try_get(res, pre, &cols[1])?,
        ))
    }
}

// to this:
impl<T, U> TryGetableMany for (T, U)
where
    T: TryGetable,
    U: TryGetable,
{
    fn try_get_many(res: &QueryResult, pre: &str, cols: &[String]) -> Result<Self, TryGetError> {
        try_get_many_with_slice_len_of(2, cols)?;
        Ok((
            T::try_get(res, pre, &cols[0])?,
            U::try_get(res, pre, &cols[1])?,
        ))
    }
}
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 a pull request may close this issue.

1 participant