diff options
Diffstat (limited to 'src/xchan.rs')
-rw-r--r-- | src/xchan.rs | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/src/xchan.rs b/src/xchan.rs index 5d1c17b..20bbe8d 100644 --- a/src/xchan.rs +++ b/src/xchan.rs @@ -29,33 +29,31 @@ enum XChanSelector<'a> { GUID(&'a str), } -pub struct XChanFetcher<'a> { - client: &'a Client, +pub struct XChan<'a> { data: Option<XChanSelector<'a>>, } -impl<'a> XChanFetcher<'a> { - pub fn new(client: &'a Client) -> XChanFetcher<'a> { - XChanFetcher { client, data: None } - } +pub fn xchan<'a>() -> XChan<'a> { + XChan { data: None } +} - pub fn by_address(&mut self, addr: &'a str) -> &mut XChanFetcher<'a> { +impl<'a> XChan<'a> { + pub fn by_address(&mut self, addr: &'a str) -> &mut XChan<'a> { self.data = Some(XChanSelector::Address(addr)); self } - pub fn by_hash(&mut self, hash: &'a str) -> &mut XChanFetcher<'a> { + pub fn by_hash(&mut self, hash: &'a str) -> &mut XChan<'a> { self.data = Some(XChanSelector::Hash(hash)); self } - pub fn by_guid(&mut self, guid: &'a str) -> &mut XChanFetcher<'a> { + pub fn by_guid(&mut self, guid: &'a str) -> &mut XChan<'a> { self.data = Some(XChanSelector::GUID(guid)); self } - pub fn fetch(&self) -> Result<String, Error> { - self.client - .fetch_stream("xchan", &self.data.as_ref().unwrap()) + pub fn fetch(&self, client: &Client) -> Result<String, Error> { + client.fetch_stream("xchan", &self.data.as_ref().unwrap()) } } |