Constraining V::Value when implementing serde deserializer

I'm learning how to implement various serde things at the moment and I've run into an interesting situation.

Given

fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
       ...
    }

I want to be able to specify that V::Value should also implement some other trait. In the case of postgres, FromSql.

fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
        V::Value: FromSql<'de>
    {
       ...
    }

My idea right now is to hack it by implementing a "Phantom" type that implements FromSql and throws away the data just to check if the returned value is Some.

I need a concrete type because

  self.row.get<_, V::Value>(index)

V::Value may not implement FromSql

Anyone have any other ideas?

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.