dflemstr / rq

Record Query - A tool for doing record analysis and transformation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Update to Serde 1.0

dtolnay opened this issue · comments

I'm attempting to upgrade the sub-crate serde-protobuf to Serde 1.0.2, here

I feel like I'm close but I have one issue left. In de.rs:

#[inline]
fn visit_value<'de, V>(descriptors: &descriptor::Descriptors,
                  descriptor: &descriptor::FieldDescriptor,
                  value: value::Value,
                  visitor: V)
                  -> error::Result<V::Value>
    where V: serde::de::Visitor<'de>
{
    match value {
        value::Value::Bool(v) => visitor.visit_bool(v),
        value::Value::I32(v) => visitor.visit_i32(v),
        value::Value::I64(v) => visitor.visit_i64(v),
        value::Value::U32(v) => visitor.visit_u32(v),
        value::Value::U64(v) => visitor.visit_u64(v),
        value::Value::F32(v) => visitor.visit_f32(v),
        value::Value::F64(v) => visitor.visit_f64(v),
        value::Value::Bytes(v) => visitor.visit_byte_buf(v),
        value::Value::String(v) => visitor.visit_string(v),
        value::Value::Message(m) => {
            if let descriptor::FieldType::Message(d) = descriptor.field_type(descriptors) {
                visitor.visit_map(MessageVisitor::new(descriptors, d, m))
            } else {
                panic!("A field with a message value doesn't have a message type!")
            }
        },
        value::Value::Enum(e) => {
            if let descriptor::FieldType::Enum(d) = descriptor.field_type(descriptors) {
                visitor.visit_str(d.value_by_number(e).unwrap().name())
            } else {
                panic!("A field with an enum value doesn't have an enum type!")
            }
        },
    }
}

I get this:

cargo build
   Compiling serde-protobuf v0.5.0 (file:///home/sevagh/repos/rq/serde-protobuf)
error[E0495]: cannot infer an appropriate lifetime for autoref due to conflicting requirements
   --> de.rs:367:67
    |
367 |             if let descriptor::FieldType::Message(d) = descriptor.field_type(descriptors) {
    |                                                                   ^^^^^^^^^^
    |
note: first, the lifetime cannot outlive the anonymous lifetime #2 defined on the body at 355:0...
   --> de.rs:355:1
    |
355 | {
    | ^
note: ...so that reference does not outlive borrowed content
   --> de.rs:367:56
    |
367 |             if let descriptor::FieldType::Message(d) = descriptor.field_type(descriptors) {
    |                                                        ^^^^^^^^^^
note: but, the lifetime must be valid for the lifetime 'de as defined on the body at 355:0...
   --> de.rs:355:1
    |
355 | {
    | ^
note: ...so that types are compatible (expected serde::de::MapAccess<'de>, found serde::de::MapAccess<'_>)
   --> de.rs:368:25
    |
368 |                 visitor.visit_map(MessageVisitor::new(descriptors, d, m))
    |                         ^^^^^^^^^

e

It's a bit tricky for me to understand. Any pointers?

The input descriptors and descriptor need to be &'de references. Otherwise they may not live as long as the MessageVisitor expects them to.

Thanks, made a PR: #160

Seems to pass the unit tests and it works inside my crate as well.

New PR for serde-avro: #163

Finally, finally, this is done!