Skip to content

Implement FromCqlVal for frame::value::MaybeUnset  #429

@DayOfThePenguin

Description

@DayOfThePenguin

Migrating this from the comments on #421 because it's a separate discrete feature.

I tried implementing this myself, but the problem I'm running into is that since associative type binds aren't supported yet, I can't do it for any generic V that implements Value (i.e. impl FromCqlVal for crate::frame::value::MaybeUnset<V: Value>. The workaround for this seems to be to implement it for MaybeUnset<CqlValue> and accept that you have to match for each variant of CqlValue. Something like:

impl FromCqlVal<CqlValue> for crate::frame::value::MaybeUnset<CqlValue> {
    fn from_cql(cql_val: CqlValue) -> Result<Self, FromCqlValError> {
        match cql_val {
            CqlValue::Ascii(_) => todo!(),
            CqlValue::Boolean(_) => todo!(),
            CqlValue::Blob(_) => todo!(),
            CqlValue::Counter(_) => todo!(),
            CqlValue::Decimal(_) => todo!(),
            CqlValue::Date(_) => todo!(),
            CqlValue::Double(_) => todo!(),
            CqlValue::Duration(_) => todo!(),
            CqlValue::Empty => todo!(),
            CqlValue::Float(_) => todo!(),
            CqlValue::Int(_) => todo!(),
            CqlValue::BigInt(_) => todo!(),
            CqlValue::Text(_) => todo!(),
            CqlValue::Timestamp(_) => todo!(),
            CqlValue::Inet(_) => todo!(),
            CqlValue::List(_) => todo!(),
            CqlValue::Map(_) => todo!(),
            CqlValue::Set(_) => todo!(),
            CqlValue::UserDefinedType { keyspace, type_name, fields } => todo!(),
            CqlValue::SmallInt(_) => todo!(),
            CqlValue::TinyInt(_) => todo!(),
            CqlValue::Time(_) => todo!(),
            CqlValue::Timeuuid(_) => todo!(),
            CqlValue::Tuple(_) => todo!(),
            CqlValue::Uuid(_) => todo!(),
            CqlValue::Varint(_) => todo!(),
        }
    }
}

It's not clear to me how to implement the base case for MaybeUnset::Unset though. I have a feeling that changes to the generic implementation of from_cql<Option<CqlValue>> (lines 61-71 in cql_to_rust.rs) might be required too?

Originally posted by @DayOfThePenguin in #421 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions