summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2020-05-03 11:56:06 +0200
committerMatthias Beyer <mail@beyermatthias.de>2020-05-12 21:35:08 +0200
commit87789ae9f22d9469e7b1e451bc00485ae9b5f2e3 (patch)
treeb693bf0839585037d57f30febd5b60ebd7288301
parent6401c0ec505a9e8d7119928879cd8f97a3699239 (diff)
Switch to actix as runtime
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--Cargo.toml5
-rw-r--r--src/main.rs10
-rw-r--r--src/repository/client.rs14
3 files changed, 17 insertions, 12 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 2186eca..8149941 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -19,7 +19,7 @@ edition = "2018"
is-match = "0.1"
failure = "0.1"
futures = "0.3"
-ipfs-api = "0.7"
+ipfs-api = { version = "0.7", features = ["actix"], default-features = false }
serde = "1"
serde_derive = "1"
serde_json = "1"
@@ -39,3 +39,6 @@ xdg = "2"
structopt = "0.3"
web-view = "0.6"
handlebars = "3"
+actix-rt = "1"
+actix-web = "2"
+
diff --git a/src/main.rs b/src/main.rs
index 4444e52..043680b 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -16,6 +16,8 @@ extern crate itertools;
extern crate xdg;
extern crate handlebars;
extern crate web_view;
+extern crate actix_rt;
+extern crate actix_web;
#[macro_use] extern crate failure;
#[macro_use] extern crate is_match;
@@ -63,7 +65,7 @@ use crate::types::util::Version;
use std::process::exit;
-#[tokio::main]
+#[actix_rt::main]
async fn main() -> Result<()> {
let cli = cli()?;
let _ = env_logger::init();
@@ -89,16 +91,14 @@ async fn main() -> Result<()> {
let api_url = config.get_api_url().clone();
let api_port = config.get_api_port().clone();
- tokio::spawn(async move {
- App::load(name, key, &api_url, api_port)
- })
+ App::load(name, key, &api_url, api_port)
} else {
// ask user for name(s)
// boot repository
// load App object
unimplemented!()
}
- }.await?;
+ };
let html_content = include_str!("../assets/index.html");
diff --git a/src/repository/client.rs b/src/repository/client.rs
index 59542c8..62a6826 100644
--- a/src/repository/client.rs
+++ b/src/repository/client.rs
@@ -5,6 +5,7 @@ use std::ops::Deref;
use ipfs_api::IpfsClient;
use failure::Error;
use failure::err_msg;
+use failure::AsFail;
use futures::future::Future;
use futures::future::FutureExt;
use futures::stream::Stream;
@@ -36,7 +37,7 @@ impl ClientFassade {
IpfsClient::new(host, port)
.map(Arc::new)
.map(|c| ClientFassade(c))
- .map_err(Into::into)
+ .map_err(|e| Error::from(e.as_fail()))
}
pub async fn get_raw_bytes<H: AsRef<IPFSHash>>(&self, hash: H) -> Result<Vec<u8>, Error> {
@@ -46,7 +47,7 @@ impl ClientFassade {
.cat(hash.as_ref())
.map_ok(|b| b.to_vec())
.try_concat()
- .map(|r| r.map_err(Error::from))
+ .map(|r| r.map_err(|e| Error::from(e.as_fail())))
.await
}
@@ -57,7 +58,7 @@ impl ClientFassade {
.add(Cursor::new(data))
.await
.map(|res| IPFSHash::from(res.hash))
- .map_err(Into::into)
+ .map_err(|e| Error::from(e.as_fail()))
}
pub async fn publish(&self, key: &str, hash: &str) -> Result<IPNSHash, Error> {
@@ -67,7 +68,7 @@ impl ClientFassade {
.name_publish(hash, false, None, None, Some(key))
.await
.map(|res| IPNSHash::from(res.value))
- .map_err(Into::into)
+ .map_err(|e| Error::from(e.as_fail()))
}
pub async fn resolve(&self, ipns: IPNSHash) -> Result<IPFSHash, Error> {
@@ -76,7 +77,7 @@ impl ClientFassade {
.name_resolve(Some(&ipns), true, false)
.await
.map(|res| IPFSHash::from(res.path))
- .map_err(Into::into)
+ .map_err(|e| Error::from(e.as_fail()))
}
}
@@ -108,7 +109,8 @@ impl TypedClientFassade {
.and_then(|data| {
debug!("Got data, building object: {:?}", data);
- serde_json::from_slice(&data).map_err(Error::from)
+ serde_json::from_slice(&data)
+ .map_err(|e| Error::from(e.as_fail()))
})
}