Struct noosphere_core::data::MemoIpld
source · pub struct MemoIpld {
pub parent: Option<Cid>,
pub headers: Vec<(String, String)>,
pub body: Cid,
}Expand description
A basic Memo. A Memo is a history-retaining structure that pairs inline headers with a body CID.
Fields§
§parent: Option<Cid>An optional pointer to the previous version of the DAG
headers: Vec<(String, String)>Headers that are associated with the content of this DAG
body: CidA pointer to the body content
Implementations§
source§impl MemoIpld
impl MemoIpld
sourcepub async fn try_compare_body<S: BlockStore>(&self, store: &S) -> Result<bool>
pub async fn try_compare_body<S: BlockStore>(&self, store: &S) -> Result<bool>
If the body of this memo is different from it’s parent, returns true.
sourcepub async fn diff_headers(
&self,
other: &MemoIpld
) -> Result<Vec<(String, String)>>
pub async fn diff_headers( &self, other: &MemoIpld ) -> Result<Vec<(String, String)>>
Get the list of headers that either do not appear in other, or have a different value from a same-named header in other
sourcepub async fn for_body<S: BlockStore, Body: Serialize + BlockStoreSend>(
store: &mut S,
body: Body
) -> Result<MemoIpld>
pub async fn for_body<S: BlockStore, Body: Serialize + BlockStoreSend>( store: &mut S, body: Body ) -> Result<MemoIpld>
Initializes a memo for the provided body, persisting the body to storage and returning the memo. Note that only the body is persisted, not the memo that wraps it.
sourcepub async fn branch_from<S: BlockStore>(cid: &Cid, store: &S) -> Result<Self>
pub async fn branch_from<S: BlockStore>(cid: &Cid, store: &S) -> Result<Self>
Loads a memo from the provided CID, initializes a copy of it, sets the copy’s parent to the provided CID and cleans signature information from the copy’s headers; the new memo is returned.
sourcepub async fn sign<Credential: KeyMaterial>(
&mut self,
credential: &Credential,
authorization: Option<&Authorization>
) -> Result<()>
pub async fn sign<Credential: KeyMaterial>( &mut self, credential: &Credential, authorization: Option<&Authorization> ) -> Result<()>
Sign the memo’s body CID, adding the signature and proof as headers in the memo
sourcepub fn get_header(&self, name: &str) -> Vec<String>
pub fn get_header(&self, name: &str) -> Vec<String>
Retreive the set of headers that matches the given string name
sourcepub fn get_first_header(&self, name: &str) -> Option<String>
pub fn get_first_header(&self, name: &str) -> Option<String>
Retrieve the first header value (if any) that matches the given header name
sourcepub fn expect_header(&self, name: &str, value: &str) -> Result<()>
pub fn expect_header(&self, name: &str, value: &str) -> Result<()>
Asserts that a header with the given name and value exists in the memo
sourcepub fn replace_first_header(&mut self, name: &str, value: &str)
pub fn replace_first_header(&mut self, name: &str, value: &str)
Replaces the value of the first header that matches name with provided value
sourcepub fn replace_headers(&mut self, new_headers: Vec<(String, String)>)
pub fn replace_headers(&mut self, new_headers: Vec<(String, String)>)
Replaces all headers in the memo whose names match names that occur in the input list of headers. If multiple headers with the same name already occur in the memo, all of them will be removed. If multiple headers with the same name already occur in the input list, all of them will be included in the new set of headers.
sourcepub fn remove_header(&mut self, name: &str)
pub fn remove_header(&mut self, name: &str)
Removes all headers with the given name from the memo
sourcepub fn content_type(&self) -> Option<ContentType>
pub fn content_type(&self) -> Option<ContentType>
Helper to quickly deserialize a content-type (if any) from the memo