Ambiguous type and fully qualified syntax

let message: dnstap::Dnstap = prost::Message::decode(&mut data_frame)?;
let inner_message: dnstap::Message = message.message.unwrap();
match inner_message.r#type   {
            dnstap::Message::Type::CLIENT_RESPONSE => {

            }
            _=> {

            }
        }

gives me an error saying

--> 140:13
|
| dnstap::Message::Type::CLIENT_RESPONSE => {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use fully-qualified syntax: <dnstap::Message as Trait>::Type

I am unable to understand what does fully qualified syntax mean ?

It works ifI do

if inner_message.r#type == 6

It's right there in the error message:

<dnstap::Message as Trait>::Type

(Of course, Trait must be subsituted with the actual name of the trait that defines the Type associated type.)

This is what I see in the generated file

pub struct Message {
    /// One of the Type values described above.
    #[prost(enumeration="message::Type", required, tag="1")]
    pub r#type: i32,
...
...
}
pub mod message {
    pub enum Type {
     ...
     CLIENT_RESPONSE=6,
...
}
}

Not sure what the trait should refer to ?

That's because you wrote dnstap::Message, which refers to a type, so dnstap::Message::Type is supposed to be an associated type. Since it is not found for Message it might be defined in the implementation of some trait, so the compiler suggest you to be explicit about what trait you mean. But actually all of this seems meaningless in your case since you probably meant message with a lowercase m, which is the module which contains Type.

The following code works

if inner_message.r#type == dnstap::message::Type::ClientResponse as i32

How do I make this into a match ?

match inner_message.r#type {
            dnstap::message::Type::ClientResponse => {

            } 
            _=> {
                
            }
        }
error[E0308]: mismatched types --> | | match inner_message.r#type { | -------------------- this expression has type `i32` | dnstap::message::Type::ClientResponse => { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found enum `dnstap::message::Type` |
|

234 | ClientResponse = 6,
| ------------------ unit variant defined here

error: aborting due to previous error

For more information about this error, try rustc --explain E0308.

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.