Are External Dependencies Allowed for Rust Implementations in AI Engineering From Scratch?
No, external crates are strictly prohibited; all Rust implementations in the ai-engineering-from-scratch repository must use only the standard library and compile with a single rustc --edition 2021 command.
The rohitg00/ai-engineering-from-scratch curriculum enforces a strict "stdlib-first" policy to ensure learners master core language concepts without relying on third-party abstractions. According to the repository's contribution guidelines, every Rust lesson must function as a single file using only the Rust standard library, explicitly banning external dependencies typically managed through Cargo.toml.
The Official Policy on External Dependencies
The dependency restrictions are codified in AGENTS.md (lines 55-63), which defines the toolchain requirements for each language. For Rust, the specification reads:
Rust | stdlib only (single-file
rustc --edition 2021)
This entry establishes that no external crates are permitted in any lesson submission. Unlike conventional Rust development that leverages Cargo for dependency management, the curriculum requires code that compiles directly with the standalone Rust compiler. This constraint eliminates hidden complexity from third-party libraries and forces manual implementation of algorithms—such as random number generators or matrix operations—that are often imported via crates.io.
Anatomy of a Compliant Rust Implementation
A valid submission must satisfy three technical requirements derived from the source policy:
- No Cargo.toml: The presence of a Cargo manifest file indicates external dependency usage, which violates the stdlib-only rule.
- Single-file compilation: Code must compile with
rustc --edition 2021 filename.rswithout additional flags for linking external libraries. - Standard library exclusivity: All imports must derive from
std::orcore::crates included with the Rust distribution.
Working Example: KV Cache and RNG in Pure Stdlib
The file phases/10-llms-from-scratch/12-inference-optimization/code/main.rs demonstrates how to implement functionality typically requiring external crates—such as deterministic random number generation—using only standard library primitives.
// phases/10-llms-from-scratch/12-inference-optimization/code/main.rs
// Stdlib‑only implementation of a deterministic RNG and KV cache.
use std::collections::HashMap;
use std::f32::consts::PI;
// Simple xorshift64 RNG (no extern crate)
struct Rng { state: u64 }
impl Rng {
fn new(seed: u64) -> Self {
let mut s = seed;
if s == 0 { s = 0xdead_beef_cafe_babe; }
Rng { state: s }
}
fn next_u64(&mut self) -> u64 {
let mut x = self.state;
x ^= x << 13;
x ^= x >> 7;
x ^= x << 17;
self.state = x;
x
}
fn uniform(&mut self) -> f32 {
(self.next_u64() as f32 + 1.0) / (u64::MAX as f32 + 2.0)
}
// …additional helper methods…
}
fn main() {
let mut rng = Rng::new(42);
println!("Uniform sample: {}", rng.uniform());
}
This implementation avoids the popular rand crate by defining a custom Rng struct implementing the xorshift64 algorithm. The code compiles and executes with a single command as specified in the lesson documentation:
rustc --edition 2021 main.rs -o /tmp/inf && /tmp/inf
Key Files Defining the Constraint
Understanding the dependency restrictions requires examining:
AGENTS.md: Contains the canonical dependency table banning external crates for Rust implementations.phases/10-llms-from-scratch/12-inference-optimization/code/main.rs: Demonstrates stdlib-only patterns for LLM inference optimization.phases/*/code/*.rs: All Rust lesson files follow the same no-dependency pattern.
Summary
- External dependencies are strictly forbidden in ai-engineering-from-scratch Rust lessons according to
AGENTS.md. - Only the standard library may be used; no external crates via Cargo.toml.
- Single-file compilation with
rustc --edition 2021is the required build method. - Algorithms must be implemented from scratch, such as the xorshift64 RNG in the KV cache example, rather than imported from crates.io.
Frequently Asked Questions
Can I use the rand crate for random number generation in my submission?
No, the rand crate and any other external dependencies are explicitly prohibited. You must implement algorithms like random number generation manually using standard library types, as demonstrated in the Rng struct within phases/10-llms-from-scratch/12-inference-optimization/code/main.rs.
Why does the curriculum ban external crates for Rust implementations?
The restriction exists to enforce a "stdlib-first" pedagogy that prioritizes understanding core language concepts and algorithmic implementation over API consumption. By prohibiting third-party libraries, the curriculum ensures learners comprehend the underlying mechanics of systems like neural network inference rather than relying on opaque abstractions.
How do I handle missing stdlib features without external dependencies?
You must implement required functionality manually using primitive types and standard collections. For example, the repository provides a manual xorshift64 implementation instead of using a cryptographic RNG, and uses std::collections::HashMap for caching rather than specialized crates.
Is Cargo allowed for local development if I don't commit the Cargo.toml?
While you might experiment locally, the official submission must compile with rustc --edition 2021 as a single file without any Cargo infrastructure. The AGENTS.md policy specifically mandates single-file compilation, making Cargo-based workflows non-compliant regardless of whether the manifest is committed.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →