Skip to content

Instantly share code, notes, and snippets.

View working.rs
use crate::models::links::{Link, LinkJson, LinkNew, LinkUpdate};
use crate::Pool;
use actix_web::{web, Error, HttpResponse};
use diesel::dsl::insert_into;
use diesel::prelude::*;
use regex::Regex;
use reqwest::Url;
pub async fn add_link(
View gist:e92fc0f9417a6bf9ecb6ca30324e1c3f
use crate::models::images::{Image, ImageJson, ImageNew, ImageUpdate};
use crate::Pool;
use actix_web::{web, Error, HttpResponse};
use diesel::dsl::insert_into;
use std::path::Path;
use anyhow::{Result};
use tokio::fs::File;
use tokio::io::{AsyncWriteExt};
use diesel::prelude::*;
@kilroyjones
kilroyjones / issue_with_errors.rs
Last active Aug 1, 2020
Issue with errors and async
View issue_with_errors.rs
//In using the automate library which is an async library that talks to rust I had two
//different errors I needed to deal with. One was automate::Error and the other was
//Box<dyn std::error::Error> from a call to an API in a module I'd created.
//Automate: https://crates.io/crates/automate
//mycode.rs
async fn weather(ctx: &mut Context, data: &MessageCreateDispatch) -> Result<(), Error> {
...
@kilroyjones
kilroyjones / async-openweather.rs
Created Jul 31, 2020
Async openweather example
View async-openweather.rs
async fn get_response(location: &str) -> Result<String, reqwest::Error> {
let base_http = "https://api.openweathermap.org/data/2.5/weather?q=".to_string();
let units = "metric";
let addr = base_http + &location + "&appid=" + API_KEY + "&units=" + &units;
let json = reqwest::get(&addr)
.await?
.text()
.await?;
Ok(json)
}
@kilroyjones
kilroyjones / add.rs
Last active Jul 30, 2020
Rust add function using any parameter type.
View add.rs
extern crate num;
use num::{ToPrimitive, Float};
fn add<T, R, U>(a: T, b: R) -> U
where
T: ToPrimitive,
R: ToPrimitive,
U: Float,
{
You can’t perform that action at this time.