|
1 | 1 | //! Serialization for client-server communication. |
2 | 2 |
|
3 | | -use std::any::Any; |
4 | 3 | use std::io::Write; |
5 | 4 | use std::num::NonZero; |
6 | 5 |
|
@@ -259,71 +258,3 @@ impl<'a, S, T: for<'s> Decode<'a, 's, S>> Decode<'a, '_, S> for Vec<T> { |
259 | 258 | vec |
260 | 259 | } |
261 | 260 | } |
262 | | - |
263 | | -/// Simplified version of panic payloads, ignoring |
264 | | -/// types other than `&'static str` and `String`. |
265 | | -pub enum PanicMessage { |
266 | | - StaticStr(&'static str), |
267 | | - String(String), |
268 | | - Unknown, |
269 | | -} |
270 | | - |
271 | | -impl From<Box<dyn Any + Send>> for PanicMessage { |
272 | | - fn from(payload: Box<dyn Any + Send + 'static>) -> Self { |
273 | | - if let Some(s) = payload.downcast_ref::<&'static str>() { |
274 | | - return PanicMessage::StaticStr(s); |
275 | | - } |
276 | | - if let Ok(s) = payload.downcast::<String>() { |
277 | | - return PanicMessage::String(*s); |
278 | | - } |
279 | | - PanicMessage::Unknown |
280 | | - } |
281 | | -} |
282 | | - |
283 | | -impl From<PanicMessage> for Box<dyn Any + Send> { |
284 | | - fn from(val: PanicMessage) -> Self { |
285 | | - match val { |
286 | | - PanicMessage::StaticStr(s) => Box::new(s), |
287 | | - PanicMessage::String(s) => Box::new(s), |
288 | | - PanicMessage::Unknown => { |
289 | | - struct UnknownPanicMessage; |
290 | | - Box::new(UnknownPanicMessage) |
291 | | - } |
292 | | - } |
293 | | - } |
294 | | -} |
295 | | - |
296 | | -impl PanicMessage { |
297 | | - pub fn as_str(&self) -> Option<&str> { |
298 | | - match self { |
299 | | - PanicMessage::StaticStr(s) => Some(s), |
300 | | - PanicMessage::String(s) => Some(s), |
301 | | - PanicMessage::Unknown => None, |
302 | | - } |
303 | | - } |
304 | | - |
305 | | - pub fn into_string(self) -> Option<String> { |
306 | | - match self { |
307 | | - PanicMessage::StaticStr(s) => Some(s.into()), |
308 | | - PanicMessage::String(s) => Some(s), |
309 | | - PanicMessage::Unknown => None, |
310 | | - } |
311 | | - } |
312 | | -} |
313 | | - |
314 | | -impl<S> Encode<S> for PanicMessage { |
315 | | - #[inline] |
316 | | - fn encode(self, w: &mut Buffer, s: &mut S) { |
317 | | - self.as_str().encode(w, s); |
318 | | - } |
319 | | -} |
320 | | - |
321 | | -impl<S> Decode<'_, '_, S> for PanicMessage { |
322 | | - #[inline] |
323 | | - fn decode(r: &mut &[u8], s: &mut S) -> Self { |
324 | | - match Option::<String>::decode(r, s) { |
325 | | - Some(s) => PanicMessage::String(s), |
326 | | - None => PanicMessage::Unknown, |
327 | | - } |
328 | | - } |
329 | | -} |
0 commit comments