diff --git a/src/inliner.rs b/src/inliner.rs index 621a4da..a298ed1 100644 --- a/src/inliner.rs +++ b/src/inliner.rs @@ -18,12 +18,8 @@ impl Inliner { store, } } -} - -impl Iterator for Inliner { - type Item = Result>; - fn next(&mut self) -> Option { + pub fn attempt(mut self) -> Result> { for node in self.iterator.clone() { match node { Ipld::Link(cid) => { @@ -37,10 +33,10 @@ impl Iterator for Inliner { self.stack.push(Ipld::Map(outer)); } else { - return Some(Err(Stuck { + return Err(Stuck { need: cid, - inliner: self.clone(), - })); + inliner: self, + }); } } @@ -65,9 +61,9 @@ impl Iterator for Inliner { let root = self .stack .pop() - .expect("should have exactly one item on the stack"); + .expect("should have exactly one item on the stack"); // FIXME change stack to nonempty? - Some(Ok(root)) + Ok(root) } } @@ -82,12 +78,12 @@ impl Stuck { &self.need } - pub fn ignore(self) -> Inliner { - self.inliner - } - pub fn resolve(&mut self, ipld: Ipld) -> &Inliner { self.inliner.iterator.inbound.push(ipld); &self.inliner } + + pub fn ignore(&mut self) -> &Inliner { + self.resolve(Ipld::Link(self.need)) + } } diff --git a/src/lib.rs b/src/lib.rs index f44c4ca..775778f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,31 +4,31 @@ pub mod inliner; pub mod iterator; pub mod store; -use crate::{extractor::Extractor, inliner::Inliner, store::Store}; -use libipld::codec::{Codec, Encode}; -use libipld::{cid::Version, Ipld}; -use multihash::MultihashDigest; +// use crate::{extractor::Extractor, inliner::Inliner, store::Store}; +// use libipld::codec::{Codec, Encode}; +// use libipld::{cid::Version, Ipld}; +// use multihash::MultihashDigest; // FIXME more defaults // TODO consider making these properties of the store (to and from?) // FIXME most of this has moved to the store -pub fn inline(ipld: Ipld, store: S) -> Result> { - Inliner::new(ipld, store) - .next() - .expect("should be nonempty") -} - -pub fn extract>( - ipld: Ipld, - store: &mut impl Store, - codec: C, - digester: &D, - cid_version: Version, -) where - Ipld: Encode, -{ - for (cid, dag) in Extractor::new(ipld, codec, digester, cid_version) { - store.put_keyed(cid, dag); - } -} +// pub fn inline(ipld: Ipld, store: S) -> Result> { +// Inliner::new(ipld, store) +// .next() +// .expect("should be nonempty") +// } +// +// pub fn extract>( +// ipld: Ipld, +// store: &mut impl Store, +// codec: C, +// digester: &D, +// cid_version: Version, +// ) where +// Ipld: Encode, +// { +// for (cid, dag) in Extractor::new(ipld, codec, digester, cid_version) { +// store.put_keyed(cid, dag); +// } +// } diff --git a/src/store.rs b/src/store.rs index 21ddd09..de47441 100644 --- a/src/store.rs +++ b/src/store.rs @@ -2,7 +2,7 @@ mod memory; use crate::cid::{cid_of, CidError}; use crate::extractor::Extractor; -use crate::inliner::{Inliner, Stuck}; +use crate::inliner::Inliner; use libipld::{ cid, cid::{Cid, Version}, @@ -50,10 +50,8 @@ pub trait Store: Clone { Ok(buffer) } - fn inline(self, ipld: Ipld) -> Result> { + fn inline(self, ipld: Ipld) -> Inliner { Inliner::new(ipld, self) - .next() - .expect("should be nonempty because Ipld was just handed to the Inliner") } fn extract>(