Skip to content

Instantly share code, notes, and snippets.

View toksdotdev's full-sized avatar

toks toksdotdev

View GitHub Profile
@toksdotdev
toksdotdev / assert_nom_locate.rs
Last active March 28, 2022 13:35
Simple macro to assert on nom parser and nom_locate result
/// Perform assertion on a location span type.
macro_rules! assert_span {
($actual: expr, line = $value: expr) => {
assert_eq!($actual.location_line(), $value);
};
($actual: expr, fragment = $value: expr) => {
assert_eq!(*$actual.fragment(), $value);
};
($actual: expr, column = $value: expr) => {
assert_eq!($actual.get_column(), $value);
@toksdotdev
toksdotdev / why-size-of-option-t-is-doubled.md
Last active May 9, 2022 16:21
An explanation of why the size of Option<T> is always often double the size of T

Someone asked a question some weeks back about why size_of::<Option<T>> is always double. Answer is because of alignment.

Explanation

How are Rust enum represented in C?

C doesn't have the ability to directly represent complex Rust enum, hence, the need for a workaround. To understand that, let's take a look at how Option<i32> is represnted in C.

E.g. Given:

use super::RoundRobinStrategy;
use crate::balancer::StrategyProducer;
use crate::Target;
use futures::future::abortable;
use futures::stream::AbortHandle;
use futures::stream::Abortable;
use std::sync::atomic::AtomicBool;
use std::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering;
use std::sync::Arc;
@toksdotdev
toksdotdev / vesper-dark.json
Created February 12, 2024 23:44 — forked from bdsqqq/vesper-dark.json
Vesper theme for zed.dev
{
"$schema": "https://zed.dev/schema/themes/v0.1.0.json",
"name": "Vesper",
"author": "Rauno Freiberg",
"themes": [
{
"name": "Vesper",
"appearance": "dark",
"style": {
"border": "#101010",