pub fn from_bytes(bytes: &[u8]) -> Result<Self, Error>
  where Self: Sized {
    let mut r = ByteCursor::new(bytes.to_vec());
    let result = match Self::read(&mut r) {
      Ok(r) => r,
      Err(_) => return Err(Error::Varint(decode::Error::Overflow)),
    };
    // There were more bytes supplied than read
    if bytes.len() >= r.position() as usize + 1 {
      return Err(Error::InvalidSize(r.get_ref().len().try_into().expect(
        "Currently the maximum size is 255, therefore always fits into usize",
      )));
    }

    Ok(result)
  }
/// Parses a multihash from a bytes.
///
/// You need to make sure the passed in bytes have the correct length. The
/// digest length needs to match the `size` value of the multihash.
Parses a multihash from a bytes.
You need to make sure the passed in bytes have the correct length. The
digest length needs to match the `size` value of the multihash.
Parses a multihash from a bytes . You need to make sure the passed in bytes have the correct length . The digest length needs to match the ` size ` value of the multihash .
pub fn from_bytes(bytes: &[u8]) -> Result<Self, Error>
  where Self: Sized {
    let mut r = ByteCursor::new(bytes.to_vec());
    let result = match Self::read(&mut r) {
      Ok(r) => r,
      Err(_) => return Err(Error::Varint(decode::Error::Overflow)),
    };
    // There were more bytes supplied than read
    if bytes.len() >= r.position() as usize + 1 {
      return Err(Error::InvalidSize(r.get_ref().len().try_into().expect(
        "Currently the maximum size is 255, therefore always fits into usize",
      )));
    }
    Ok(result)
  }
pub fn from_bytes ( bytes : & [ u8 ] ) -> Result < Self , Error > where Self : Sized { let mut r = ByteCursor :: new ( bytes . to_vec ( ) ) ; let result = match Self :: read ( & mut r ) { Ok ( r ) => r , Err ( _ ) => return Err ( Error :: Varint ( decode :: Error :: Overflow ) ) , } ; // There were more bytes supplied than read if bytes . len ( ) >= r . position ( ) as usize + 1 { return Err ( Error :: InvalidSize ( r . get_ref ( ) . len ( ) . try_into ( ) . expect ( " " , ) ) ) ; } Ok ( result ) }
Parses a multihash from a bytes.
Parses a multihash from a bytes .
bytes
&[u8]
bytes
&[u8]