bc_ur/
ur_decodable.rs

1use crate::ur::UR;
2
3use anyhow::Result;
4
5use dcbor::CBORTaggedDecodable;
6
7/// A type that can be decoded from a UR.
8pub trait URDecodable: CBORTaggedDecodable {
9    fn from_ur(ur: impl AsRef<UR>) -> Result<Self> where Self: Sized {
10        ur.as_ref().check_type(Self::cbor_tags()[0].name().as_ref().unwrap().clone())?;
11        Self::from_untagged_cbor(ur.as_ref().clone().into())
12    }
13
14    fn from_ur_string(ur_string: impl Into<String>) -> Result<Self> where Self: Sized {
15        Self::from_ur(UR::from_ur_string(ur_string)?)
16    }
17}
18
19impl<T> URDecodable for T where T: CBORTaggedDecodable { }