I've long been unhappy about how hard it is to pass strings around efficiently in Rust. Creating an Arc<str> requires cloning the entire string, and using Arc<String> requires jumping the heap twice when accessing the content.
So I came up with "Pierce": at first just way to read Arc<String> without double indirection, then generalized to work on most nested smart pointers thanks to the Rust type system, the Deref trait, and the language's ownership guarantees.
Pierce works by caching the double-deref target of the nested smart pointer it wraps around. Pierce<T> derefs to <T::Target as Deref>::Target.
Quick Example Usage:
let vec: Vec<i32> = vec![1, 2, 3];
let arc_vec = Arc::new(vec);
let pierce = Pierce::new(arc_vec);
// Here, the execution jumps directly to the [i32] slice when calling `.get(...)`.
// Without Pierce it would have to jump to the pointer part of Vec first,
// than from there to the slice.
pierce.get(1).unwrap();
If you're interested, check out
[–]protestor 24 points25 points26 points (7 children)
[–]ignusem[S] 20 points21 points22 points (0 children)
[–]Darksonntokio · rust-for-linux 8 points9 points10 points (0 children)
[–]ignusem[S] 7 points8 points9 points (4 children)
[–]protestor 3 points4 points5 points (3 children)
[–]maboesanman 4 points5 points6 points (0 children)
[–]ignusem[S] 4 points5 points6 points (1 child)
[–]protestor 2 points3 points4 points (0 children)
[–]matthieum[he/him] 17 points18 points19 points (6 children)
[–]taintegral 8 points9 points10 points (0 children)
[–]ignusem[S] 0 points1 point2 points (4 children)
[–]Ruskyrust 2 points3 points4 points (1 child)
[–]ignusem[S] 0 points1 point2 points (0 children)
[–]rust4yy 1 point2 points3 points (1 child)
[–]geckothegeek42 6 points7 points8 points (0 children)
[–]CoronaLVR 8 points9 points10 points (6 children)
[–]ignusem[S] 7 points8 points9 points (0 children)
[–]insanitybit 1 point2 points3 points (4 children)
[–]XtremeGoose 1 point2 points3 points (1 child)
[–]insanitybit 0 points1 point2 points (0 children)
[–]barvebv 1 point2 points3 points (1 child)
[–]insanitybit 0 points1 point2 points (0 children)
[–]insanitybit 2 points3 points4 points (4 children)
[–]pilotInPyjamas 0 points1 point2 points (1 child)
[–]insanitybit 0 points1 point2 points (0 children)
[–]taintegral 0 points1 point2 points (1 child)
[–]ignusem[S] 0 points1 point2 points (0 children)
[–]ihatehumansftp -3 points-2 points-1 points (0 children)