Skip to content

Instantly share code, notes, and snippets.

View felipesere's full-sized avatar
🦀
Doing Rust stuff

Felipe Seré felipesere

🦀
Doing Rust stuff
View GitHub Profile
spellmaster/crates/test_terminal on  main ●●
● ❯ cargo c
Checking test_terminal v0.1.0 (/Users/felipesere/Development/rust/spellmaster/crates/test_terminal)
error[E0277]: the trait bound `&Input: std::io::Read` is not satisfied
--> src/lib.rs:25:36
|
25 | Term::read_write_pair(&*x, &*y)
| --------------------- ^^^ the trait `std::io::Read` is not implemented for `&Input`
| |
| required by a bound introduced by this call
@felipesere
felipesere / gist:77e82b5e0bea3d40da6e210063211deb
Created September 26, 2021 21:33
Desire to build a clean API will stashing away resources for later use...
struct Provider<A> {
api: A,
tracked_resources: TrackedResources,
}
struct Api { ...};
impl Api {
fn create_thing() -> ThingBuilder {...}
}
@felipesere
felipesere / downcating.rs
Created September 20, 2021 07:33
Show how I want to track homogenous resources in a provider but still return a specific type so users can still interact with it - even if read-only.
pub struct AwsProvider(Inner);
struct Inner {
creds: Credentials,
region: String,
tracked_resources: RwLock<Vec<Box<dyn Resource<Aws>>>>,
}
// TODO: it would be nice if this could magically put the
// reosurce on the heap (Arc<Box<...>>) and then return
@felipesere
felipesere / from_global.rs
Created May 19, 2021 18:32
Example using clap_derive and its expansion.
use clap::Clap;
#[derive(Debug, PartialEq, Clap)]
struct Opt {
#[clap(global = true, long)]
global: bool,
#[clap(subcommand)]
sub: Subcommands,
}
@felipesere
felipesere / diagnostics.go
Created February 19, 2021 21:46
Cute little diagnostics errors in go
package diagnostics
import (
"errors"
"fmt"
"sort"
"strings"
)
type Diagnostic struct {
[crates/oro-tree/src/lib.rs:33] &f = MainPackage {
name: "sane-flags",
version: "0.3.1",
requires: true,
dependencies: {
"@babel/code-frame": Package {
name: None,
version: "7.10.4",
requires: {
"@babel/highlight": "^7.10.4",
let mut app = tide::with_state(state.clone());
app.middleware(RequestLogger::new());
/*
app.at("/").get(tide::redirect("/files/index.html"));
app.at("/files").strip_prefix().get(StaticFilesEndpoint {
root: "./tldr-github-parcel/dist".into(),
});
*/
let root_for_files = "./tldr-github-parcel/dist";
@felipesere
felipesere / sample.rs
Created January 21, 2020 21:22
Race conditions? Block?
pub fn add_items_to_track(
db: Arc<dyn Db>,
client: Arc<dyn ClientForRepositories + Send + Sync>,
id: i32,
items: Vec<api::ItemToTrack>,
) -> Result<()> {
log::info!("We were about to add {:?} to {}", items, id);
if let Some(repo) = db.find_repo(id) {
let mut tasks = FuturesUnordered::new();
for item in items {
@felipesere
felipesere / Repo.svelte
Created January 15, 2020 13:32
'items' does not update when clicking any of the tabs
<script>
import { fade } from 'svelte/transition';
import Github from './Github.svelte';
import GlowBox from '../GlowBox.svelte';
import Indicator, {Recency} from './Indicator.svelte';
import Settings from '../settings/Settings.svelte';
import Content from './Content.svelte';
export let repo
let showSettings = false;
let items = filterItems(repo, 'all');
// What I write right now
pub fn all(conn: &Conn) -> Result<Vec<FullStoredRepo>> {
use schema::repos::dsl::*;
let rs: Vec<StoredRepo> = repos.load(conn).with_context(|| "getting all repos")?;
let ids: Vec<i32> = rs.iter().map(|r| r.id).collect();
use schema::issues::dsl::{issues, repo_id as issue_repo_id};
let isx = issues