1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
use crate::ur::UR;

use dcbor::CBORTaggedDecodable;

/// A type that can be decoded from a UR.
pub trait URDecodable: CBORTaggedDecodable {
    fn from_ur(ur: &UR) -> anyhow::Result<Self> where Self: Sized {
        ur.check_type(Self::cbor_tags()[0].name().as_ref().unwrap())?;
        Self::from_untagged_cbor(ur.cbor())
    }

    fn from_ur_string<T: Into<String>>(ur_string: T) -> anyhow::Result<Self> where Self: Sized {
        Self::from_ur(&UR::from_ur_string(ur_string)?)
    }
}