Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Guides writing and reviewing idiomatic Rust using Apollo GraphQL's best practices handbook: ownership, errors, performance, testing, docs.
78% 96%+17 ptsof test cases passed
Passed 22 of 23 test cases with the skill, and 18 of 23 without it.
3 of 3 safety checks passed
Not used yet
Many higher level languages hide memory management, typically passing by value (copy data) or passing by reference (reference to shared data) without worrying about allocation, heap, stack, ownership and lifetimes, it is all delegated to the garbage collector or VM. Here is a comparison on this topic between a few languages:
| Language | Value Types | Reference/Pointer Types | Async Model & Types | Manual Memory |
|---|---|---|---|---|
| Python | None | Everything is a reference | async def, await, Task, coroutines and asyncio.Future | ❌ Not Allowed |
| Javascript | Primitives | Objects | async/await, Promise, setTimeout. single threaded event loop | ❌ Not Allowed |
| Java | Primitives | Objects | Future<T>, threads, Loom (green threads) | ❌ Almost none & not recommended |
| Go | Values are copied unless using &T | Pointers (*T, &T), escape analysis | goroutines, channels, sync.Mutex, context.Context | ⚠️ Limited |
| C | Primitives and structs supported | Raw pointers T* and *void | Threads, event loops (libuv, libevent) | ✅ Fully |
| C++ | Primitives and references | Raw T* and smart pointers shared_ptr and unique_ptr | threads, std::future, std::async, (since c++ 20 co_await/coroutines) | ✅ Mostly |
| Rust | Primitives, Arrays, impl Copy | &T, &mut T, Box<T>, Arc<T> | async/await, tokio, Future, JoinHandle, Send + Sync | ✅🔒 Safe and Explicit |
Rust tracks pointers using Send and Sync traits:
Send means data can move across threads.Sync means data can be referenced from multiple threads.A pointer is thread-safe only if the data behind it is.
| Pointer Type | Short Description | Send + Sync? | Main Use |
|---|---|---|---|
&T | Shared reference | Yes | Shared access |
&mut T | Exclusive mutable reference | No, not Send | Exclusive mutation |
Box<T> | Heap-allocated owning pointer | Yes, if T: Send + Sync | Heap allocation |
Rc<T> | Single-threaded ref counted pointer | No, neither | Multiple owners (single-thread) |
Arc<T> | Atomic ref counter pointer | Yes | Multiple owners (multi-thread) |
Cell<T> | Interior mutability for copy types | No, not Sync | Shared mutable, non-threaded |
RefCell<T> | Interior mutability (dynamic borrow checker) | No, not Sync | Shared mutable, non-threaded |
Mutex<T> | Thread-safe interior mutability with exclusive access | Yes | Shared mutable, threaded |
RwLock<T> | Thread-safe shared readonly access OR exclusive mutable access | Yes | Shared mutable, threaded |
OnceCell<T> | Single-thread one-time initialization container (interior mutability ONCE) | No, not Sync | Simple lazy value initialization |
LazyCell<T> | A lazy version of OnceCell<T> that calls function closure to initialize | No, not Sync | Complex lazy value initialization |
OnceLock<T> | Thread-safe version of OnceCell<T> | Yes | Multi-thread single init |
LazyLock<T> | Thread-safe version of LazyCell<T> | Yes | Multi-thread complex init |
*const T/*mut T | Raw Pointers | No, user must ensure safety manually | Raw memory / FFI |
Skills that do similar work, with their benchmark result.
Next to this one in the catalogue, plus more from the same author.