This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Fetch several rows from 1 or more pages from an API. Concatenate all | |
// the rows together. | |
function paginated<Request, Response, Row>( | |
// A fetch function that retrieves a single page. Intended to wrap a fetch() | |
// API call (so that you can add your own headers, auth, response parsing, | |
// etc) | |
fetcher: (url: Request, cancel?: AbortSignal) => Promise<Response>, | |
// Given a response, get the URL of the next page, or null if this was the | |
// last page. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub fn use_atomic(value: &AtomicU64, op: impl FnOnce(NonZeroU64) -> NonZeroU64) { | |
loop { | |
let current = value.swap(0, Ordering::AcqRel); | |
match NonZeroU64::new(current) { | |
Some(current) => { | |
let computed = op(current); | |
// It might be more appropriate to use compare_exchange here | |
value.store(computed.get(), Ordering::Release); | |
break; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let data = vec![1, 2, 3, 4]; | |
let iter = generate::generate![1, 2, ..data]; | |
let data: Vec<i32> = iter.collect(); | |
println!("{:#?}", data); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::{ | |
future::Future, | |
panic::{catch_unwind, UnwindSafe}, | |
pin::Pin, | |
task::{Context, Poll}, | |
}; | |
use pin_project::pin_project; | |
#[pin_project] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
impl<'i, B> FromPercentEncoded<'i> for Cow<'i, B> | |
where | |
B: ToOwned, | |
&'i B: FromPercentEncoded<'i>, | |
<&'i B as FromPercentEncoded<'i>>::StrError: MaybeCannotGrowError, | |
<&'i B as FromPercentEncoded<'i>>::BytesError: MaybeCannotGrowError, | |
B::Owned: FromPercentEncoded<'i>, | |
{ | |
type BytesError = CowError< | |
<B::Owned as FromPercentEncoded<'i>>::BytesError, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Webtoon Enhancer | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description try to take over the world! | |
// @author You | |
// @match https://www.webtoons.com/en/* | |
// @icon https://www.google.com/s2/favicons?domain=webtoons.com | |
// @grant none | |
// @require https://raw.githubusercontent.com/Lucretiel/comics-enhance/master/enhance.js |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use autodefault::autodefault; | |
#[derive(Debug, Default)] | |
struct Big1 { | |
a: i32, | |
b: i32, | |
c: i32, | |
d: i32, | |
e: i32, | |
f: i32, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait PrioritySearcher<'a, T> { | |
fn test(&mut self, item: &'a T) -> bool; | |
fn next_best(self) -> Option<&'a T>; | |
} | |
impl<'a, F, T> PrioritySearcher<'a, T> for F | |
where F: FnMut(&'a T) -> bool | |
{ | |
fn test(&mut self, item: &'a T) -> bool { | |
(self)(item) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub trait BuildFlags: Sized { | |
type Error; | |
fn try_build_flags(payload: [u8; 2]) -> Result<Self, Self::Error>; | |
} | |
pub struct Headers<F> { | |
pub id: u16, | |
pub flags: F, | |
pub qdcount: u16, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::{convert::TryInto, time::Duration}; | |
use nom::IResult; | |
use nom::{ | |
bits::{bits, streaming::take as take_bits}, | |
number::streaming::be_u16, | |
sequence::tuple, | |
Parser, | |
}; | |
use nom_supreme::{error::ErrorTree, parser_ext::ParserExt}; |