This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

Merge two functions

+31 -45
+2 -2
inline_ipld/src/extractor.rs
··· 198 198 CidGeneric::try_from("bafyreickxqyrg7hhhdm2z24kduovd4k4vvbmfmenzn7nc6pxg6qzjm2v44") 199 199 .unwrap(); 200 200 201 - let inline = InlineIpld::new(arr_cid, ipld!([1, 2, 3])); 201 + let inline = InlineIpld::new(Some(arr_cid), ipld!([1, 2, 3])); 202 202 203 203 let mut observed: BTreeMap<Cid, Ipld> = BTreeMap::new(); 204 204 for (cid, node) in Extractor::new(&inline, DagCborCodec, &Sha2_256, Version::V1) { ··· 230 230 CidGeneric::try_from("bafyreihnubkcms63243zlfgnwiugmk6ijitz63me7bqf455ia2fpbn4ceq") 231 231 .unwrap(); 232 232 233 - let inline = InlineIpld::new(arr_cid, ipld!([1, 2, 3])); 233 + let inline = InlineIpld::new(Some(arr_cid), ipld!([1, 2, 3])); 234 234 235 235 let mut observed: BTreeMap<Cid, Ipld> = BTreeMap::new(); 236 236 for (cid, node) in Extractor::new(&inline, DagCborCodec, &Sha2_256, Version::V1) {
+2 -4
inline_ipld/src/inliner/traits.rs
··· 36 36 /// # use pretty_assertions::assert_eq; 37 37 /// # 38 38 /// let store = MemoryStore::new(); // NOTE: completely blank through entire example 39 - /// let missing_cid: Cid = CidGeneric::try_from( 40 - /// "bafyreickxqyrg7hhhdm2z24kduovd4k4vvbmfmenzn7nc6pxg6qzjm2v44", 41 - /// ) 39 + /// let missing_cid: Cid = CidGeneric::try_from("bafyreickxqyrg7hhhdm2z24kduovd4k4vvbmfmenzn7nc6pxg6qzjm2v44") 42 40 /// .unwrap(); 43 41 /// 44 42 /// let dag = ipld!({"a": 1, "b": missing_cid}); ··· 177 175 pub fn stub(mut self, ipld: Ipld) -> Box<I> { 178 176 self.inliner 179 177 .deref_mut() 180 - .resolve(InlineIpld::new(self.needs, ipld).into()); 178 + .resolve(InlineIpld::new(Some(self.needs), ipld).into()); 181 179 182 180 self.inliner 183 181 }
+27 -39
inline_ipld/src/ipld/inline.rs
··· 19 19 /// # use inline_ipld::{cid, InlineIpld}; 20 20 /// # use libipld::{ipld, Ipld}; 21 21 /// # 22 - /// let inlined = InlineIpld::new_inherit_link(ipld!([1, 2, 3])); 22 + /// let inlined = InlineIpld::new(None, ipld!([1, 2, 3])); 23 23 /// let ipld = ipld!({"a": 1, "b": inlined}); 24 24 /// assert_eq!(ipld, ipld!({"a": 1, "b": {"/": {".": [1, 2, 3]}}})); 25 25 /// ``` ··· 61 61 /// 62 62 /// Note that [`new`][Self::new] *does not* check that the [`Cid`] actually corresponds to the associated [`Ipld`]. 63 63 /// 64 + /// [`new`][Self::new] wraps the enclosed [`Ipld`] in the correct delimiters. 65 + /// If the `cid` field is omitted, the extracted IPLD link will inherit the CID configuration 66 + /// of its parent during extraction. // FIXME actually implement this feature whoops! 67 + /// 64 68 /// # Arguments 65 69 /// 66 - /// * `cid` - The [`Cid`] for the `"&"` field 70 + /// * `cid` - An optional [`Cid`] for the `"&"` field 67 71 /// * `ipld` - The [`Ipld`] to inline 72 + /// 73 + /// # Examples 74 + /// 75 + /// ``` 76 + /// # use inline_ipld::{cid, InlineIpld}; 77 + /// # use libipld::{ipld, Ipld}; 78 + /// # 79 + /// let observed = InlineIpld::new(None, ipld!([1, 2, 3])); 80 + /// assert_eq!(observed, ipld!({"/": {".": ipld!([1, 2, 3])}})); 81 + /// ``` 68 82 /// 69 83 /// ``` 70 84 /// # use inline_ipld::{cid, InlineIpld}; ··· 72 86 /// # use std::str::FromStr; 73 87 /// # 74 88 /// let cid: Cid = FromStr::from_str("bafyreihscx57i276zr5pgnioa5omevods6eseu5h4mllmow6csasju6eqi").unwrap(); 75 - /// assert_eq!(InlineIpld::new(cid, ipld!([1, 2, 3])), ipld!({ 89 + /// assert_eq!(InlineIpld::new(Some(cid), ipld!([1, 2, 3])), ipld!({ 76 90 /// "/": { 77 91 /// ".": ipld!([1, 2, 3]), 78 92 /// "&": cid 79 93 /// } 80 94 /// })); 81 95 /// ``` 82 - pub fn new(cid: Cid, ipld: Ipld) -> Self { 83 - InlineIpld { 84 - cid: Some(cid), 85 - ipld: ipld!({ 86 - "/": { 87 - "&": Ipld::Link(cid), 88 - ".": ipld 89 - } 90 - }), 91 - } 92 - } 93 - 94 - /// Create inline-delimited [`Ipld`], but omit the `"&"` field 95 - /// 96 - /// [`new_inherit_link`][Self::new_inherit_link] wraps the enclosed [`Ipld`] in the correct delimiters. 97 - /// It omits the `"&"` field. Per the [spec], this causes the extracted 98 - /// IPLD link to inherit the coedec and CID encoding of its parent. 99 96 /// 100 97 /// [spec]: https://github.com/ucan-wg/ipld-inline-links 101 - /// 102 - /// # Arguments 103 - /// 104 - /// * `ipld` - The [`Ipld`] to wrap in the inlined delimiter 105 - /// 106 - /// # Examples 107 - /// 108 - /// ``` 109 - /// # use inline_ipld::{cid, InlineIpld}; 110 - /// # use libipld::{ipld, Ipld}; 111 - /// # 112 - /// let observed = InlineIpld::new_inherit_link(ipld!([1, 2, 3])); 113 - /// assert_eq!(observed, ipld!({"/": {".": ipld!([1, 2, 3])}})); 114 - /// ``` 115 - pub fn new_inherit_link(ipld: Ipld) -> Self { 98 + pub fn new(cid: Option<Cid>, ipld: Ipld) -> Self { 99 + let inner = match cid { 100 + Some(link) => ipld!({".": ipld, "&": link}), 101 + None => ipld!({ ".": ipld }), 102 + }; 103 + 116 104 InlineIpld { 117 - cid: None, 118 - ipld: ipld!({"/": {".": ipld!(ipld)}}), 105 + cid, 106 + ipld: ipld!({ "/": inner }), 119 107 } 120 108 } 121 109 ··· 124 112 /// Use with caution: non-inlined [`Ipld`] can be maked as inlined with this function. 125 113 /// 126 114 /// This is used in place of [`from`][`From::from`] to highlight that no conversion or checks happen. 127 - /// If conversion is desired, use [`Self::new_inherit_link`]. 115 + /// If conversion is desired, use [`Self::new`] with the `cid` field set to [`None`]. 128 116 /// 129 117 /// # Arguments 130 118 /// ··· 170 158 /// # 171 159 /// let ipld = ipld!({"a": 1, "b": {"/": {".": [1, 2, 3]}}}); 172 160 /// let cid = cid::new(&ipld, DagCborCodec, &Sha2_256, Version::V1); 173 - /// let inlined = InlineIpld::new(cid, ipld); 161 + /// let inlined = InlineIpld::new(Some(cid), ipld); 174 162 /// assert_eq!(inlined.cid(), Some(cid)); 175 163 /// ``` 176 164 pub fn cid(&self) -> Option<Cid> {