| Crates.io | workspacer-format-imports |
| lib.rs | workspacer-format-imports |
| version | 0.1.2 |
| created_at | 2025-04-01 14:04:15.763764+00 |
| updated_at | 2025-07-13 01:12:57.388888+00 |
| description | A Rust crate for parsing, sorting, and formatting import statements across crates and workspaces. Uses RA-AP-syntax to reorganize 'use' statements by prefix, sort them alphabetically, and preserve comments. |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1614908 |
| size | 273,946 |
workspacer-format-imports is a Rust crate that provides a comprehensive framework for syntactic refinement of Rust code, specifically focusing on the organization of import statements. It aims to streamline and organize import declarations across a Rust crate or workspace for enhanced readability and maintainability.
src/imports.rs using Rust Analyzer's abstract syntax tree (RA-AP-syntax).use statements, allowing the detection and extraction of syntax elements.use statements by their prefixes, converging identical paths within braces for succinctness:
pub(crate) use std::collections::HashMap;
pub(crate) use std::collections::HashSet;
// becomes
pub(crate) use std::collections::{HashMap, HashSet};
use statements are organized in alphabetical order.use statements during reorganization.Implement the SortAndFormatImports trait to utilize the organization and formatting capabilities:
#[async_trait]
impl SortAndFormatImports for CrateHandle {
type Error = CrateError;
async fn sort_and_format_imports(&self) -> Result<(), Self::Error> {
// implementation details
}
}
Integrate the crate into a Rust workspace to standardize import formatting and bolster code clarity.
use statements.Ensure you have the Rust 2024 edition enabled to exercise all features of the crate effectively.
workspacer-format-imports is available under the MIT License.