1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
macro_rules! impl_to_cid { ($v:path) => ( impl ToCid for $v { fn to_cid(&self) -> Result<Cid, CidError> { let mut encoded = Vec::<u8>::new(); let mut cloned = self.clone(); cloned.canonicalize(); cloned.encode(&mut encoded).map_err(|_| CidError::ParsingError)?; let hashed = encode(Hash::Keccak256, &encoded).map_err(|_| CidError::ParsingError)?; let cid = Cid::new(Codec::Unknown(<Self as AssociatedCodec>::CODEC_CODE), Version::V1, &hashed); Ok(cid) } }) ; } macro_rules! codec_code { ($v:path, $c:expr) => ( impl AssociatedCodec for $v { const CODEC_CODE: u64 = $c; } ); } macro_rules! impl_canonicalize { ($v:path; $($field_name:ident),*) => ( impl Canonicalize for $v { fn canonicalize(&mut self) { $(self.$field_name.sort());* } } ); } macro_rules! impl_into_entity_kind { ($v:path, $wrapper:path) => ( impl Into<Entity> for $v { fn into(self) -> Entity { $wrapper(self) } } ); }