### Parse Crate Versions with jq (Bash) Source: https://context7.com/rust-lang/crates.io-index/llms.txt Examples using `jq` to parse crate version information from metadata files. This includes viewing all versions, finding the latest non-yanked version, checking dependencies for a specific version, and listing crates with a specific dependency. ```bash # View all versions of a crate cat ./se/rd/serde | jq -r '.vers' # Get latest non-yanked version cat ./se/rd/serde | jq -s 'map(select(.yanked == false)) | sort_by(.vers) | .[-1]' # Check dependencies for specific version cat ./se/rd/serde | jq 'select(.vers == "1.0.0") | .deps' # List all crates with a specific dependency for file in $(find . -type f); do if grep -q '"name":"tokio"' "$file" 2>/dev/null; then basename "$file" fi done ``` -------------------------------- ### Crate Metadata JSON Structure (JSON) Source: https://context7.com/rust-lang/crates.io-index/llms.txt An example of the JSON structure for a single crate version record within the crates.io index. It includes essential information like name, version, dependencies, checksum, features, and yanked status. ```json { "name": "serde", "vers": "1.0.0", "deps": [ { "name": "serde_derive", "req": "^1.0.0", "features": [], "optional": true, "default_features": true, "target": null, "kind": "normal" } ], "cksum": "f2059569fa48d0f3943a1d4691ca7e6445551869fd9725f339e682232e4e6a81", "features": { "derive": ["serde_derive"], "default": ["std"], "std": [] }, "yanked": false, "rust_version": "1.56" } ``` -------------------------------- ### Extract Dependency Information with jq (Bash) Source: https://context7.com/rust-lang/crates.io-index/llms.txt Demonstrates how to extract detailed dependency information for a specific crate version using `jq`. This includes extracting all dependencies, finding optional dependencies, checking platform-specific dependencies, and listing development dependencies. ```bash # Extract all dependencies for a version cat ./to/ki/tokio | jq 'select(.vers == "1.0.0") | .deps[] | "\(.name) \(.req)"' # Find optional dependencies cat ./se/rd/serde | jq 'select(.vers == "1.0.0") | .deps[] | select(.optional == true) | .name' # Check platform-specific dependencies cat ./3/a/a10 | jq '.deps[] | select(.target != null) | {name, target}' # List dev dependencies (kind == "dev") cat ./se/rd/serde | jq '.deps[] | select(.kind == "dev") | .name' ``` -------------------------------- ### Access Crate Metadata by Name Length (Bash) Source: https://context7.com/rust-lang/crates.io-index/llms.txt Demonstrates how to access crate metadata files based on the crate name's length, following the index's hierarchical directory structure. This allows for efficient retrieval of specific crate information. ```bash cat 1/a/a cat 2/ab/ab cat 3/a/abc cat se/rd/serde cat to/ki/tokio cat li/bc/libc ``` -------------------------------- ### Configure Crate Download URLs (YAML & bash) Source: https://context7.com/rust-lang/crates.io-index/llms.txt This section illustrates how to dynamically configure crate download endpoints, particularly within a GitHub Actions workflow. It shows YAML configuration for workflow inputs and environment variables mapping endpoint types to URLs, and bash commands for programmatically updating a `config.json` file and constructing download URLs. ```yaml # Workflow inputs define available endpoints workflow_dispatch: inputs: url: options: - "api: API on Heroku (default)" - "cdn: CloudFront CDN" - "s3_primary: S3 bucket in us-west-1" - "s3_fallback: S3 bucket in eu-west-1" # Mapped environment variables env: URL_api: "https://crates.io/api/v1/crates" URL_cdn: "https://static.crates.io/crates/{crate}/{crate}-{version}.crate" URL_s3_primary: "https://crates-io.s3-us-west-1.amazonaws.com/crates/{crate}/{crate}-{version}.crate" ``` ```bash # Update config.json programmatically jq --arg url "https://static.crates.io/crates" '.dl = $url' config.json > config.json.tmp mv config.json.tmp config.json # Construct download URL from config DL_URL=$(jq -r '.dl' config.json) CRATE="serde" VERSION="1.0.0" DOWNLOAD="${DL_URL}/${CRATE}/${CRATE}-${VERSION}.crate" curl -L "$DOWNLOAD" -o "${CRATE}-${VERSION}.crate" ``` -------------------------------- ### Download URL Configuration Source: https://context7.com/rust-lang/crates.io-index/llms.txt Explanation of how download endpoints for crates can be dynamically configured, particularly within the context of GitHub Actions. ```APIDOC ## Download URL Configuration ### Description This section covers the dynamic configuration of crate download URLs. It highlights a GitHub Actions workflow (`.github/workflows/update-dl-url.yml`) that allows operators to switch between different download endpoints (API, CDN, S3 buckets) to manage availability during outages or for load balancing. ### Method N/A (Configuration details and command-line examples) ### Endpoint N/A (Describes configuration and construction of download URLs) ### Parameters N/A ### Request Example ```yaml # Example snippet from a GitHub Actions workflow defining inputs for download endpoints workflow_dispatch: inputs: url: options: - "api: API on Heroku (default)" - "cdn: CloudFront CDN" - "s3_primary: S3 bucket in us-west-1" - "s3_fallback: S3 bucket in eu-west-1" # Example environment variables mapping input choices to actual URLs env: URL_api: "https://crates.io/api/v1/crates" URL_cdn: "https://static.crates.io/crates/{crate}/{crate}-{version}.crate" URL_s3_primary: "https://crates-io.s3-us-west-1.amazonaws.com/crates/{crate}/{crate}-{version}.crate" ``` ```bash # Example of programmatically updating a configuration file (e.g., config.json) using jq jq --arg url "https://static.crates.io/crates" '.dl = $url' config.json > config.json.tmp mv config.json.tmp config.json # Example of constructing a download URL using a configured download path DL_URL=$(jq -r '.dl' config.json) CRATE="serde" VERSION="1.0.0" DOWNLOAD="${DL_URL}/${CRATE}/${CRATE}-${VERSION}.crate" curl -L "$DOWNLOAD" -o "${CRATE}-${VERSION}.crate" ``` ### Response #### Success Response - **Constructed Download URL**: A complete URL pointing to the crate tarball, based on the active configuration. ``` -------------------------------- ### Fetch Crate Metadata via Sparse Index API (bash) Source: https://context7.com/rust-lang/crates.io-index/llms.txt Demonstrates how to interact with the crates.io sparse index API using `curl` to fetch crate metadata over HTTP without cloning the entire git repository. It includes a bash function `get_crate` that constructs the correct URL path based on crate name length rules. ```bash # Fetch crate metadata via HTTP curl https://index.crates.io/se/rd/serde # Get specific crate based on name length rules function get_crate() { local name=$1 local len=${#name} local path if [ $len -eq 1 ]; then path="1/${name}" elif [ $len -eq 2 ]; then path="2/${name}" elif [ $len -eq 3 ]; then path="3/${name:0:1}/${name}" else path="${name:0:2}/${name:2:2}/${name}" fi curl "https://index.crates.io/${path}" } # Usage get_crate "serde" get_crate "tokio" ``` -------------------------------- ### Feature Flags with jq (Bash) Source: https://context7.com/rust-lang/crates.io-index/llms.txt Shows how to query feature flag information for a specific crate version using `jq`. This includes listing all available features and checking the default features enabled for that version. ```bash # List all features for a version cat ./se/rd/serde | jq 'select(.vers == "1.0.0") | .features | keys' # Check default features cat ./se/rd/serde | jq 'select(.vers == "1.0.0") | .features.default' ``` -------------------------------- ### Verify Crate Integrity with Checksums (bash) Source: https://context7.com/rust-lang/crates.io-index/llms.txt This section demonstrates how to verify the integrity of downloaded crates using SHA256 checksums. It shows how to extract the checksum from the index, download the crate, and then use `sha256sum` to compare the checksums. It also includes a method to find all versions with a matching checksum to detect duplicate crates. ```bash # Get checksum for verification VERSION="1.0.0" CHECKSUM=$(cat ./se/rd/serde | jq -r "select(.vers == \"$VERSION\") | .cksum") # Verify downloaded crate curl -L "https://static.crates.io/crates/serde/serde-${VERSION}.crate" -o serde.crate echo "${CHECKSUM} serde.crate" | sha256sum -c # Find all versions with matching checksum (detect duplicates) TARGET_CKSUM="d1bb2d9926b9bd18e51fc8edd663e311ff3b1fb96c9d4689854f8686f7c6c216" cat ./se/rd/serde | jq -r "select(.cksum == \"$TARGET_CKSUM\") | .vers" ``` -------------------------------- ### Sparse Index HTTP API Source: https://context7.com/rust-lang/crates.io-index/llms.txt Overview of the sparse index protocol, enabling HTTP-based access to individual crate metadata instead of cloning the entire Git repository. ```APIDOC ## Sparse Index HTTP API ### Description The sparse protocol provides an alternative to cloning the entire crates.io index Git repository. It allows clients like Cargo to fetch crate metadata using simple HTTP GET requests for individual files or directories, leading to significantly faster index interactions. ### Method `GET` ### Endpoint `https://index.crates.io/{path}` Where `{path}` is determined by the crate name's length and content: - Length 1: `1/{crate}` - Length 2: `2/{crate}` - Length 3: `3/{first_char}/{crate}` - Length 4+: `{first_two_chars}/{second_two_chars}/{crate}` ### Parameters N/A (Direct HTTP GET requests) ### Request Example ```bash # Fetch crate metadata via HTTP curl https://index.crates.io/se/rd/serde # Function to get crate metadata based on name rules function get_crate() { local name=$1 local len=${#name} local path if [ $len -eq 1 ]; then path="1/${name}" elif [ $len - -eq 2 ]; then path="2/${name}" elif [ $len -eq 3 ]; then path="3/${name:0:1}/${name}" else path="${name:0:2}/${name:2:2}/${name}" fi curl "https://index.crates.io/${path}" } # Usage examples get_crate "serde" get_crate "tokio" ``` ### Response #### Success Response (200 OK) - **Crate Metadata**: JSON object containing metadata for the requested crate(s) within the specified path segment. ``` -------------------------------- ### Manage Yanked Versions (bash) Source: https://context7.com/rust-lang/crates.io-index/llms.txt This snippet provides bash commands using jq to manage yanked (retracted) crate versions. It demonstrates listing all yanked versions, counting active vs. yanked versions, and checking if a specific version has been yanked. Yanked versions are excluded from normal dependency resolution but can be explicitly used. ```bash # List yanked versions cat ./se/rd/serde | jq -r 'select(.yanked == true) | .vers' # Count yanked vs active versions echo "Active: $(cat ./se/rd/serde | jq -s 'map(select(.yanked == false)) | length')" echo "Yanked: $(cat ./se/rd/serde | jq -s 'map(select(.yanked == true)) | length')" # Check if specific version is yanked cat ./se/rd/serde | jq -e "select(.vers == \"1.0.0\") | select(.yanked == true)" > /dev/null && echo "Yanked" || echo "Active" ``` -------------------------------- ### Find Features Enabling a Dependency Source: https://context7.com/rust-lang/crates.io-index/llms.txt This section explains how to identify which features of a crate enable a specific dependency, using `jq` to parse the index data. ```APIDOC ## Find Features Enabling a Dependency ### Description This endpoint allows you to query the crate index to find which features, for a specific version of a crate, enable a given dependency. It utilizes `jq` for data parsing and filtering. ### Method N/A (Command-line example using index files) ### Endpoint N/A (Operates on local index files, e.g., `./3/a/a10`) ### Parameters N/A ### Request Example ```bash cat ./3/a/a10 | jq 'select(.vers == "0.1.0") | .features | to_entries[] | select(.value | contains(["log"])) | .key' ``` ### Response #### Success Response - **feature_name** (string) - The name of the feature that enables the specified dependency. ``` -------------------------------- ### Check Minimum Rust Version (MSRV) (bash) Source: https://context7.com/rust-lang/crates.io-index/llms.txt This section details how to check and filter crate versions based on their Minimum Rust Version (MSRV). It shows how to retrieve the `rust_version` field for a specific version and how to find all versions compatible with a given Rust toolchain version. This is crucial for ensuring compatibility. ```bash # Check MSRV for a version cat ./3/a/a10 | jq 'select(.vers == "0.3.0") | .rust_version' # Find versions compatible with Rust 1.56+ cat ./3/a/a10 | jq -r 'select(.rust_version) | select(.rust_version <= "1.56") | .vers' # List all crates requiring nightly features for file in $(find . -type f -name "*"); do if cat "$file" 2>/dev/null | jq -e '.features.nightly' > /dev/null 2>&1; echo "$file" fi done ``` -------------------------------- ### Configuration File Structure (JSON) Source: https://context7.com/rust-lang/crates.io-index/llms.txt The root `config.json` file defines the base URL for downloading crate files and the API endpoint for the crates.io index. The `dl` field uses template variables for constructing download URLs. ```json { "dl": "https://static.crates.io/crates", "api": "https://crates.io" } ``` -------------------------------- ### Find Features Enabling a Dependency (jq) Source: https://context7.com/rust-lang/crates.io-index/llms.txt This snippet uses jq to parse the crates.io index file and identify which features of a specific crate version include a given dependency. It filters by version, extracts features, and then filters entries where the feature list contains the target dependency. ```bash cat ./3/a/a10 | jq 'select(.vers == "0.1.0") | .features | to_entries[] | select(.value | contains(["log"])) | .key' ``` -------------------------------- ### Minimum Rust Version (MSRV) Source: https://context7.com/rust-lang/crates.io-index/llms.txt Details on the `rust_version` field, indicating the minimum supported Rust version for a crate release. ```APIDOC ## Minimum Rust Version (MSRV) ### Description This section explains the optional `rust_version` field found in crate metadata. This field specifies the minimum Rust compiler version required for a particular crate release, aiding Cargo in resolving dependencies that are compatible with the user's current toolchain. ### Method N/A (Command-line examples using `jq`) ### Endpoint N/A (Operates on local index files, e.g., `./3/a/a10`) ### Parameters N/A ### Request Example ```bash # Check MSRV for a version cat ./3/a/a10 | jq 'select(.vers == "0.3.0") | .rust_version' # Find versions compatible with Rust 1.56+ cat ./3/a/a10 | jq -r 'select(.rust_version) | select(.rust_version <= "1.56") | .vers' # List all crates requiring nightly features for file in $(find . -type f -name "*"); do if cat "$file" 2>/dev/null | jq -e '.features.nightly' > /dev/null 2>&1; then echo "$file" fi done ``` ### Response #### Success Response - **`rust_version`** (string) - The minimum Rust version string (e.g., `"1.56.0"`). - **`vers`** (string) - A list of crate versions compatible with a given Rust version. ``` -------------------------------- ### Checksum Verification Source: https://context7.com/rust-lang/crates.io-index/llms.txt Details on how to verify the integrity of downloaded crate tarballs using SHA256 checksums provided in the index. ```APIDOC ## Checksum Verification ### Description This section details the process of verifying the integrity of downloaded crate tarballs using SHA256 checksums. Each crate version in the index includes a checksum that Cargo uses to ensure the downloaded file has not been corrupted or tampered with before extraction. ### Method N/A (Command-line examples using `curl`, `jq`, and `sha256sum`) ### Endpoint N/A (Operates on local index files and remote crate URLs) ### Parameters N/A ### Request Example ```bash # Get checksum for verification VERSION="1.0.0" CHECKSUM=$(cat ./se/rd/serde | jq -r "select(.vers == \"$VERSION\") | .cksum") # Verify downloaded crate curl -L "https://static.crates.io/crates/serde/serde-${VERSION}.crate" -o serde.crate echo "${CHECKSUM} serde.crate" | sha256sum -c # Find all versions with matching checksum (detect duplicates) TARGET_CKSUM="d1bb2d9926b9bd18e51fc8edd663e311ff3b1fb96c9d4689854f8686f7c6c216" cat ./se/rd/serde | jq -r "select(.cksum == \"$TARGET_CKSUM\") | .vers" ``` ### Response #### Success Response (sha256sum) - **Output**: Indicates whether the checksum matches (e.g., `serde-1.0.0.crate: OK`). #### Response Example (jq) - **Output**: A list of versions (strings) that share the specified checksum. ``` -------------------------------- ### Yanked Versions Source: https://context7.com/rust-lang/crates.io-index/llms.txt Information on yanked (retracted) versions of crates, which are excluded from normal dependency resolution. ```APIDOC ## Yanked Versions ### Description This section describes 'yanked' crate versions. Yanking is a mechanism to retract a version without deleting it from the index. Yanked versions are excluded from standard dependency resolution but can still be used if explicitly requested in a lock file. ### Method N/A (Command-line examples using `jq`) ### Endpoint N/A (Operates on local index files, e.g., `./se/rd/serde`) ### Parameters N/A ### Request Example ```bash # List yanked versions cat ./se/rd/serde | jq -r 'select(.yanked == true) | .vers' # Count yanked vs active versions echo "Active: $(cat ./se/rd/serde | jq -s 'map(select(.yanked == false)) | length')" echo "Yanked: $(cat ./se/rd/serde | jq -s 'map(select(.yanked == true)) | length')" # Check if specific version is yanked cat ./se/rd/serde | jq -e "select(.vers == \"1.0.0\") | select(.yanked == true)" > /dev/null && echo "Yanked" || echo "Active" ``` ### Response #### Success Response - **Output**: For listing, a list of version strings. For counting, counts of active and yanked versions. For checking, either "Yanked" or "Active". ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.