[−][src]Struct libipld::block::Block
Block
Implementations
impl<S: StoreParams> Block<S>
[src]
pub fn new(cid: Cid, data: Vec<u8>) -> Result<Self>
[src]
Creates a new block. Returns an error if the hash doesn't match the data.
pub fn new_unchecked(cid: Cid, data: Vec<u8>) -> Self
[src]
Creates a new block without verifying the cid.
pub fn cid(&self) -> &Cid
[src]
Returns the cid.
pub fn data(&self) -> &[u8]
[src]
Returns the payload.
pub fn into_inner(self) -> (Cid, Vec<u8>)
[src]
Returns the inner cid and data.
pub fn encode<CE: Codec, T: Encode<CE> + ?Sized>(
codec: CE,
hcode: u64,
payload: &T
) -> Result<Self> where
CE: Into<S::Codecs>,
[src]
codec: CE,
hcode: u64,
payload: &T
) -> Result<Self> where
CE: Into<S::Codecs>,
Encode a block.`
pub fn decode<CD: Codec, T: Decode<CD>>(&self) -> Result<T> where
S::Codecs: Into<CD>,
[src]
S::Codecs: Into<CD>,
Decodes a block.
Example
Decoding to Ipld
:
use libipld::block::Block; use libipld::cbor::DagCborCodec; use libipld::codec_impl::Multicodec; use libipld::ipld::Ipld; use libipld::multihash::{Multihash, SHA2_256}; use libipld::store::DefaultStoreParams; let block = Block::<DefaultStoreParams>::encode(DagCborCodec, SHA2_256, "Hello World!").unwrap(); let ipld = block.decode::<DagCborCodec, Ipld>().unwrap(); assert_eq!(ipld, Ipld::String("Hello World!".to_string()));
pub fn ipld(&self) -> Result<Ipld> where
Ipld: Decode<S::Codecs>,
[src]
Ipld: Decode<S::Codecs>,
Returns the decoded ipld.
pub fn references(&self) -> Result<HashSet<Cid>> where
Ipld: Decode<S::Codecs>,
[src]
Ipld: Decode<S::Codecs>,
Returns the references.
Methods from Deref<Target = Cid>
pub fn version(&self) -> Version
Returns the cid version.
pub fn codec(&self) -> u64
Returns the cid codec.
pub fn hash(&self) -> &RawMultihash
Returns the cid multihash.
pub fn write_bytes<W>(&self, w: W) -> Result<(), Error> where
W: Write,
W: Write,
Writes the bytes to a byte stream.
pub fn to_bytes(&self) -> Vec<u8>
Returns the encoded bytes of the Cid
.
pub fn to_string_of_base(&self, base: Base) -> Result<String, Error>
Convert CID into a multibase encoded string
Example
use tiny_cid::{RAW, Cid}; use multibase::Base; use tiny_multihash::{SHA2_256, Multihash, MultihashDigest}; let mh = Multihash::new(SHA2_256, b"foo").unwrap(); let cid = Cid::new_v1(RAW, mh.to_raw().unwrap()); let encoded = cid.to_string_of_base(Base::Base64).unwrap(); assert_eq!(encoded, "mAVUSICwmtGto/8aP+ZtFPB0wQTQTQi1wZIO/oPmKXohiZueu");
Trait Implementations
impl<S> AsRef<[u8]> for Block<S>
[src]
impl<S> AsRef<Cid> for Block<S>
[src]
impl<S> Borrow<Cid> for Block<S>
[src]
impl<S: Clone> Clone for Block<S>
[src]
impl<S> Debug for Block<S>
[src]
impl<S> Deref for Block<S>
[src]
impl<S> Eq for Block<S>
[src]
impl<S> Hash for Block<S>
[src]
fn hash<SH: Hasher>(&self, hasher: &mut SH)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<S> PartialEq<Block<S>> for Block<S>
[src]
Auto Trait Implementations
impl<S> RefUnwindSafe for Block<S> where
S: RefUnwindSafe,
S: RefUnwindSafe,
impl<S> Send for Block<S> where
S: Send,
S: Send,
impl<S> Sync for Block<S> where
S: Sync,
S: Sync,
impl<S> Unpin for Block<S> where
S: Unpin,
S: Unpin,
impl<S> UnwindSafe for Block<S> where
S: UnwindSafe,
S: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T, U> AsByteSlice<T> for U where
T: ToByteSlice,
U: AsRef<[T]> + ?Sized,
T: ToByteSlice,
U: AsRef<[T]> + ?Sized,
fn as_byte_slice(&self) -> &[u8]
impl<U> AsSliceOf for U where
U: AsRef<[u8]> + ?Sized,
U: AsRef<[u8]> + ?Sized,
fn as_slice_of<T>(&self) -> Result<&[T], Error> where
T: FromByteSlice,
T: FromByteSlice,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,