Skip to main content

deser_core/ext/bridges/
uuid.rs

1use crate::error::Error;
2use crate::ext::Uuid;
3use crate::ext::known::{Bridge, impl_bridge};
4
5impl Bridge for ::uuid::Uuid {
6    type Known = Uuid;
7
8    fn to_known(&self) -> Result<Uuid, Error> {
9        Ok(Uuid(*self.as_bytes()))
10    }
11
12    fn from_known(value: Uuid) -> Result<::uuid::Uuid, Error> {
13        Ok(::uuid::Uuid::from_bytes(value.0))
14    }
15
16    fn parse_fallback(value: &str) -> Option<::uuid::Uuid> {
17        // braced and URN representations
18        value.parse().ok()
19    }
20}
21
22impl_bridge!(::uuid::Uuid);