Skip to main content

socorro_cli/models/
common.rs

1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
5use serde::{Deserialize, Deserializer, Serialize};
6
7pub fn deserialize_string_or_number<'de, D>(
8    deserializer: D,
9) -> std::result::Result<Option<String>, D::Error>
10where
11    D: Deserializer<'de>,
12{
13    let value: Option<serde_json::Value> = Option::deserialize(deserializer)?;
14    Ok(value.map(|v| match v {
15        serde_json::Value::String(s) => s,
16        serde_json::Value::Number(n) => n.to_string(),
17        other => other.to_string(),
18    }))
19}
20
21pub fn deserialize_string_or_number_required<'de, D>(
22    deserializer: D,
23) -> std::result::Result<String, D::Error>
24where
25    D: Deserializer<'de>,
26{
27    let value = serde_json::Value::deserialize(deserializer)?;
28    Ok(match value {
29        serde_json::Value::String(s) => s,
30        serde_json::Value::Number(n) => n.to_string(),
31        other => other.to_string(),
32    })
33}
34
35#[derive(Debug, Clone, Serialize, Deserialize)]
36pub struct StackFrame {
37    #[serde(default)]
38    pub frame: u32,
39    pub function: Option<String>,
40    pub file: Option<String>,
41    pub line: Option<u32>,
42    pub module: Option<String>,
43    pub offset: Option<String>,
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
47pub struct ModuleInfo {
48    pub filename: String,
49    pub debug_file: Option<String>,
50    pub debug_id: Option<String>,
51    pub code_id: Option<String>,
52    pub version: Option<String>,
53}