Skip to content

Instantly share code, notes, and snippets.

View nmrshll's full-sized avatar
🦀
rusting

Nicolas Marshall nmrshll

🦀
rusting
View GitHub Profile
@nmrshll
nmrshll / recursive_await.rs
Last active September 12, 2022 10:40
Rust recursive await
let recursive_got = {
fn try_get() -> BoxFuture<'static, String> {
async move {
if something() {
return "hello".to_string();
}
tokio::time::sleep(Duration::from_millis(500)).await;
try_get(driver).await
}
.boxed()
@nmrshll
nmrshll / field_cache.rs
Created September 12, 2022 10:40
Rust field cache
use std::future::Future;
use tokio::sync::RwLock;
pub struct Cache<T: Clone> {
item: RwLock<Option<T>>,
}
impl<T: Clone> Cache<T> {
pub fn new() -> Self {
Cache {
item: RwLock::new(None),
@nmrshll
nmrshll / fetch_public_repos.sh
Created March 30, 2023 18:13
Fetch all my public repos
curl 'https://api.github.com/users/nmrshll/repos' | jq '.[] | .html_url'
use derive_simple::DeriveSimple;
use proc_macro::TokenStream as TokenStream1;
use quote::quote;
use syn::DeriveInput;
#[proc_macro_derive(Simple)]
pub fn derive_simple(input: TokenStream1) -> TokenStream1 {
let derive_simple = DeriveSimple {
input: syn::parse_macro_input!(input as DeriveInput),
};