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 hashbrown::HashMap; | |
| use std::{ | |
| borrow::Borrow, | |
| hash::{BuildHasher, Hash, Hasher}, | |
| sync::{Mutex, MutexGuard, PoisonError}, | |
| }; | |
| pub struct LockedHashMap<K, V, S> { | |
| inner: Mutex<HashMap<K, V, S>>, |
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 split_consecutive_identical_str(s: &str) -> impl Iterator<Item = (u8, usize)> + '_ { | |
| split_consecutive_identical(s.as_bytes()) | |
| } | |
| fn split_consecutive_identical(mut seq: &[u8]) -> impl Iterator<Item = (u8, usize)> + '_ { | |
| std::iter::from_fn(move || { | |
| let (&first, rest) = seq.split_first()?; | |
| let cut_off = rest | |
| .iter() | |
| .position(|&ch| ch != first) |
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
| struct Z; | |
| struct S<T>(T); | |
| trait Add<Rhs> { | |
| type Sum; | |
| } | |
| type SumOf<N, M> = <N as Add<M>>::Sum; | |
| impl<N> Add<N> for Z { |
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 serde::Deserialize; | |
| struct HNil; | |
| impl<'de> Deserialize<'de> for HNil { | |
| fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> | |
| where | |
| D: serde::Deserializer<'de>, | |
| { | |
| deserializer.deserialize_any(serde::de::IgnoredAny)?; |
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 ConstZero { | |
| const ZERO: Self; | |
| } | |
| macro_rules! impl_primitive { | |
| ($($ty:ty)*) => { | |
| $( | |
| impl ConstZero for $ty { | |
| const ZERO: Self = 0; | |
| } |
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
| struct AutoDo<T, F> { | |
| value: T, | |
| action: F, | |
| } | |
| struct DoOnDrop<'a, T, F: FnMut(&mut T)>(&'a mut AutoDo<T, F>); | |
| impl<T, F> AutoDo<T, F> { | |
| fn new(value: T, action: F) -> Self { | |
| Self { value, action } |
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
| #[derive(Clone)] | |
| struct Lexer<'a> { | |
| s: &'a str, | |
| } | |
| impl<'a> Lexer<'a> { | |
| fn of(s: &'a str) -> Self { | |
| Self { s } | |
| } |
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
| macro_rules! iota_consts { | |
| ( | |
| $iota:ident: $($tt:tt)* | |
| ) => { | |
| iota_consts!( | |
| $iota(0, $iota): $($tt)* | |
| ); | |
| }; | |
| ( |
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
| #[allow(dead_code)] | |
| const fn is_ascii_lowercase(s: &str) -> bool { | |
| let s = s.as_bytes(); | |
| let len = s.len(); | |
| let mut i = 0; | |
| while i < len { | |
| if !s[i].is_ascii() || s[i].is_ascii_uppercase() { | |
| return false; | |
| } | |
| i += 1; |
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
| macro_rules! prefixes { | |
| (match $value:ident { | |
| $($prefix:literal .. $(if $condition:expr)? => $arm:expr,)* | |
| _ => $catch_all:expr $(,)? | |
| }) => {{ | |
| #[allow(dead_code)] | |
| fn non_repeating() { | |
| #[warn(unreachable_patterns)] | |
| match "" { | |
| $($prefix => (),)* |