sl4f_lib/location/
types.rs

1// Copyright 2020 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5use fidl_fuchsia_location_position::{Position, PositionExtras};
6use serde::{Serialize, Serializer};
7
8#[derive(Serialize)]
9#[serde(remote = "Position")]
10struct PositionDef {
11    pub latitude: f64,
12    pub longitude: f64,
13    #[serde(with = "PositionExtrasDef")]
14    pub extras: PositionExtras,
15}
16
17#[derive(Serialize)]
18struct PositionExtrasDef {
19    pub accuracy_meters: Option<f64>,
20    pub altitude_meters: Option<f64>,
21}
22
23impl PositionExtrasDef {
24    // We implement this manually instead of using #[serde(remote = "PositionExtras")]
25    // to uphold FIDL's guarantee that adding table fields is source compatible.
26    fn serialize<S: Serializer>(
27        &PositionExtras { accuracy_meters, altitude_meters, .. }: &PositionExtras,
28        serializer: S,
29    ) -> Result<S::Ok, S::Error> {
30        Self { accuracy_meters, altitude_meters }.serialize(serializer)
31    }
32}
33
34#[derive(Serialize)]
35pub struct PositionSerializer(#[serde(with = "PositionDef")] pub Position);