A String Slice Needs a Character Boundary
Rust string ranges use UTF-8 byte offsets. Learn why a valid byte position can still be an invalid slice boundary, and when character iteration is insufficient for visible text.
Topic · 104 stories · page 3 of 5
104 stories tagged rust on AI Tamer, newest first.
Rust string ranges use UTF-8 byte offsets. Learn why a valid byte position can still be an invalid slice boundary, and when character iteration is insufficient for visible text.
PhantomData occupies no storage, yet its chosen type tells Rust about logical ownership, lifetimes, variance, and auto traits. Pick the marker that matches the actual relationship.
A pinned future can contain fields with different movement rules. Structural projection makes those rules explicit, and unsafe projection must preserve them for the field’s lifetime.
A poisoned Rust mutex signals that a thread panicked while holding the lock. Recovery starts with checking the shared state’s invariants.
A weak reference can remember an Arc allocation without keeping its value alive. Access depends on whether upgrade succeeds.
Choose a Tokio channel by what each receiver needs after a pause: the latest value or messages sent in order.
Rust's Vec may reserve more space than requested. The useful guarantee is a capacity floor based on the current length.
Rust scoped threads can borrow local data because the scope joins them before returning. A small example shows where the borrowing boundary sits.
A Rust receiver can keep waiting after the workers finish if a sender is still alive. Here is how to close the channel and let the receive loop end.
A standard mutex works well for short updates in async Rust. Learn when holding its guard across an await can deadlock, and when Tokio’s async mutex is worth its cost.
Tokio’s fair semaphore can make a small request wait behind a large one, even while a permit is available. Here is why and what to check.
Rust cleans up values when they leave scope. Dropping a lock guard early can make its mutex available sooner.
Rust runs `Drop` when values are destroyed, but `Drop` cannot await a future. Give asynchronous resources an explicit shutdown path while `AsyncDrop` remains experimental.
A C enum can carry a value with no matching Rust variant. Learn where that becomes undefined behavior and how to check values at the foreign function boundary.
Rust's `RefCell` allows mutation through shared access. Its borrow checks happen at runtime, so conflicting access can panic or return an error.
A Rust library can reserve room for new error variants. Downstream callers need a deliberate fallback when matching them.
Rust warns when important results or futures are ignored. Callers can still discard them explicitly, so the warning cannot guarantee that an outcome was handled.
Use Rust's mem::take to move a value from a mutable field without cloning it. The field receives its type's default value.
Use Rust’s OnceLock to share a lazily initialized model client across threads. Learn what happens when initialization panics and when a failed result is stored.
Rust’s HashMap iterates in arbitrary order. Sort entries before producing snapshots or other output that needs a stable order.
Two crates in an agent CLI can request different features from the same dependency. Here is how Cargo combines those requests and how to trace them.
Trim and inspect borrowed prompt text, then make an owned copy only when an edit or a caller requires one.
Cloning an Arc shares the same model allocation. Arc::make_mut copies the model when another Arc still owns it.
Serde checks untagged enum variants in order. When two variants accept the same JSON object, their order decides which one the program receives.