From b636ff58b1d56520df2cd50928b29f31680c5fca Mon Sep 17 00:00:00 2001 From: asonix Date: Sun, 12 May 2019 12:24:45 -0500 Subject: [PATCH] Update README --- Cargo.toml | 2 +- README.md | 64 ++++++++++++++++++++++++++++++------------------------ 2 files changed, 37 insertions(+), 29 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 76465f4..b1dc31a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "actix-webfinger" description = "Types and helpers to create and fetch Webfinger resources" -version = "0.2.0-beta.1" +version = "0.2.0-beta.2" license = "GPL-3.0" authors = ["asonix "] repository = "https://git.asonix.dog/asonix/actix-webfinger" diff --git a/README.md b/README.md index 59e7a02..40827f2 100644 --- a/README.md +++ b/README.md @@ -9,46 +9,51 @@ First, add Actix Webfinger as a dependency ```toml [dependencies] -actix = "0.7" -actix-web = "0.7" -actix-webfinger = "0.1" +actix = "0.8" +actix-web = "1.0.0-beta.3" +actix-webfinger = "0.2.0-beta.2" ``` Then use it in your application #### Client Example ```rust -use actix::{Actor, System}; -use actix_web::client::ClientConnector; +use actix::System; +use actix_web::client::Connector; use actix_webfinger::Webfinger; -use futures::Future; +use futures::{future::lazy, Future}; use openssl::ssl::{SslConnector, SslMethod}; +use std::error::Error; -fn main() { - let sys = System::new("asonix"); +fn main() -> Result<(), Box> { + let sys = System::new("sir-boops"); - let ssl_conn = SslConnector::builder(SslMethod::tls()).unwrap().build(); - let conn = ClientConnector::with_connector(ssl_conn).start(); + let ssl_conn = SslConnector::builder(SslMethod::tls())?.build(); + let conn = Connector::new().ssl(ssl_conn).finish(); - let fut = Webfinger::fetch(conn, "asonix@asonix.dog", "localhost:8000", false) - .map(move |w: Webfinger| { - println!("asonix's webfinger:\n{:#?}", w); + let fut = lazy(move || { + Webfinger::fetch(conn, "asonix@asonix.dog", "localhost:8000", false) + .map(move |w: Webfinger| { + println!("asonix's webfinger:\n{:#?}", w); - System::current().stop(); - }) - .map_err(|e| eprintln!("Error: {}", e)); + System::current().stop(); + }) + .map_err(|e| eprintln!("Error: {}", e)) + }); actix::spawn(fut); - let _ = sys.run(); + sys.run()?; + Ok(()) } ``` #### Server Example ```rust -use actix_web::server; +use actix_web::{web::Data, App, HttpServer}; use actix_webfinger::{Resolver, Webfinger}; use futures::{future::IntoFuture, Future}; +use std::error::Error; #[derive(Clone, Debug)] pub struct MyState { @@ -57,13 +62,13 @@ pub struct MyState { pub struct MyResolver; -impl Resolver for MyResolver { +impl Resolver> for MyResolver { type Error = actix_web::error::JsonPayloadError; fn find( account: &str, domain: &str, - state: &MyState, + state: &Data, ) -> Box, Error = Self::Error>> { let w = if domain == state.domain { Some(Webfinger::new(&format!("{}@{}", account, domain))) @@ -75,15 +80,18 @@ impl Resolver for MyResolver { } } -fn main() { - server::new(|| { - actix_webfinger::app::(MyState { - domain: "asonix.dog".to_owned(), - }) +fn main() -> Result<(), Box> { + HttpServer::new(|| { + App::new() + .data(MyState { + domain: "asonix.dog".to_owned(), + }) + .service(actix_webfinger::resource::<_, MyResolver>()) }) - .bind("127.0.0.1:8000") - .unwrap() - .run(); + .bind("127.0.0.1:8000")? + .run()?; + + Ok(()) } ```