Preview of the proposed up-rust native-frame-model branch (up-rust b6b99c6d, up-spec f0e9b17) — not released documentation. branch · write-up

up_rust/
serialization_error.rs

1/********************************************************************************
2 * Copyright (c) 2026 Contributors to the Eclipse Foundation
3 *
4 * See the NOTICE file(s) distributed with this work for additional
5 * information regarding copyright ownership.
6 *
7 * This program and the accompanying materials are made available under the
8 * terms of the Apache License Version 2.0 which is available at
9 * https://www.apache.org/licenses/LICENSE-2.0
10 *
11 * SPDX-License-Identifier: Apache-2.0
12 ********************************************************************************/
13
14#[derive(Debug, Clone)]
15/// Error produced when a value cannot be serialized or deserialized.
16pub struct SerializationError(String);
17
18impl std::fmt::Display for SerializationError {
19    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20        write!(f, "{}", self.0)
21    }
22}
23
24impl std::error::Error for SerializationError {}
25
26impl SerializationError {
27    /// Creates a serialization error with the given message.
28    pub fn new(msg: impl Into<String>) -> Self {
29        Self(msg.into())
30    }
31}
32
33#[cfg(feature = "protobuf-support")]
34impl From<protobuf::Error> for SerializationError {
35    fn from(err: protobuf::Error) -> Self {
36        Self::new(format!("protobuf error: {}", err))
37    }
38}