refactor: generic magic for addressable/asmultihash
ci/woodpecker/push/woodpecker Pipeline was successful Details
ci/woodpecker/manual/woodpecker Pipeline failed Details

feat/destringify
Tomáš Mládek 2023-08-29 13:11:48 +02:00
parent 62c3478741
commit 6fb0d5f1b6
3 changed files with 12 additions and 4 deletions

View File

@ -242,6 +242,8 @@ pub trait Addressable: AsMultihash {
}
}
impl<T> Addressable for T where T: AsMultihash {}
#[cfg(test)]
mod tests {
use url::Url;

View File

@ -1,4 +1,4 @@
use crate::addressing::{Address, Addressable};
use crate::addressing::Address;
use crate::error::UpEndError;
use crate::hash::{b58_decode, sha256hash, AsMultihash, AsMultihashError, UpMultihash};
use chrono::NaiveDateTime;
@ -110,9 +110,6 @@ impl AsMultihash for InvariantEntry {
}
}
impl Addressable for Entry {}
impl Addressable for InvariantEntry {}
impl EntryValue {
pub fn to_string(&self) -> Result<String, UpEndError> {
let (type_char, content) = match self {

View File

@ -154,6 +154,15 @@ pub trait AsMultihash {
fn as_multihash(&self) -> Result<UpMultihash, AsMultihashError>;
}
impl<T> AsMultihash for T
where
T: AsRef<[u8]>,
{
fn as_multihash(&self) -> Result<UpMultihash, AsMultihashError> {
sha256hash(self)
}
}
#[cfg(test)]
mod tests {
use crate::hash::{b58_decode, b58_encode};