Help:: Serde field attribute deserialize_with

Hi,

I want to read two values from the input data stream within the deserialize function. How can I do this? I can't find anything about this in the documentation or anywhere else.

Any ideas? Best thanks!

    pub fn deserialize<'de, D>(d: D) -> std::result::Result<f64, D::Error>
    where
        D: Deserializer<'de>,
    {
        let (s1, s2): (String, String) = Seq::deserialize(d)?;

        // do something useful with the strings
    }

I got this error message and found no function/solution to solve it.

error[E0433]: failed to resolve: use of undeclared type `Seq`
  --> src/main.rs:87:42
   |
87 |         let (s1, s2): (String, String) = Seq::deserialize(d)?;
   |                                          ^^^ use of undeclared type `Seq`

Can you give some example data and the struct you want to deserialize into?

The input data stream is NMEA e.g. "...,4223.23,N,..." and I want to deserialize that into a f64 float.

Tuples are part of the Serde data model and small tuples implement Deserialize, so you should be able to change this:

let (s1, s2): (String, String) = Seq::deserialize(d)?;

into this:

let (s1, s2): (String, String) = Deserialize::deserialize(d)?;

Of course, you need to first use serde::Deserialize; for this to work.

It works like this, thank you

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.