// This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/.
use std::fmt::Display;
use serde::{Deserialize, Serialize}; use serde_json::Value as JsonValue;
/// This type represents all possible errors that can occur when serializing or deserializing an object from/to JSON. #[derive(Debug)] pubstruct ObjectError(serde_json::Error);
/// An object that can be serialized into JSON. /// /// Objects are defined by their structure in the metrics definition. /// /// This is essentially a wrapper around serde's `Serialize`/`Deserialize`, /// but in a way we can name it for our JSON (de)serialization. pubtrait ObjectSerialize { /// Deserialize the object from its JSON representation. /// /// Returns an error if deserialization fails. /// This should not happen for glean_parser-generated and later serialized objects. fn from_str(obj: &str) -> Result<Self, ObjectError> where Self: Sized;
/// Serialize this object into a JSON string. fn into_serialized_object(self) -> Result<JsonValue, ObjectError>;
}
impl<V> ObjectSerialize for V where
V: Serialize,
V: for<'de> Deserialize<'de>,
{ fn from_str(obj: &str) -> Result<Self, ObjectError> {
serde_json::from_str(obj).map_err(ObjectError)
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.