aboutsummaryrefslogtreecommitdiffstats
path: root/src/xchan.rs
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2020-01-03 23:32:44 +0100
committerHarald Eilertsen <haraldei@anduin.net>2020-01-03 23:32:44 +0100
commit0c76f0c9727a512475e29b5d099b5b7188f72052 (patch)
treed1c2b59458c62116447fa2d885113afe6a5378da /src/xchan.rs
parent5f96d9981a6d041f5c8a464cda10a0dc371060f8 (diff)
downloadrust-zotapi-0c76f0c9727a512475e29b5d099b5b7188f72052.tar.gz
rust-zotapi-0c76f0c9727a512475e29b5d099b5b7188f72052.tar.bz2
rust-zotapi-0c76f0c9727a512475e29b5d099b5b7188f72052.zip
Move Client out of the api objects.
Also make constructor functions in the zotapi namespace.
Diffstat (limited to 'src/xchan.rs')
-rw-r--r--src/xchan.rs22
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())
}
}