diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d12a53f55..88c90dfb3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,12 +31,11 @@ jobs: - name: Install Rust uses: actions-rs/toolchain@v1 with: - toolchain: stable - target: ${{ matrix.target }} - components: rustfmt, clippy + toolchain: nightly + components: rustfmt - name: Cargo fmt - run: cargo fmt --check + run: cargo +nightly fmt --check release-binary: needs: tests diff --git a/.rustfmt.toml b/.rustfmt.toml new file mode 100644 index 000000000..37b232534 --- /dev/null +++ b/.rustfmt.toml @@ -0,0 +1,3 @@ +reorder_imports = true +imports_granularity = "crate" +group_imports = "StdExternalCrate" diff --git a/crates/ctranslate2-bindings/build.rs b/crates/ctranslate2-bindings/build.rs index 6529bf66e..09cad311e 100644 --- a/crates/ctranslate2-bindings/build.rs +++ b/crates/ctranslate2-bindings/build.rs @@ -1,7 +1,7 @@ +use std::{env, path::PathBuf}; + use cmake::Config; use rust_cxx_cmake_bridge::read_cmake_generated; -use std::env; -use std::path::PathBuf; fn main() { // Tell cargo to invalidate the built crate whenever the wrapper changes diff --git a/crates/rust-cxx-cmake-bridge/src/lib.rs b/crates/rust-cxx-cmake-bridge/src/lib.rs index 885f208bd..088330808 100644 --- a/crates/rust-cxx-cmake-bridge/src/lib.rs +++ b/crates/rust-cxx-cmake-bridge/src/lib.rs @@ -1,5 +1,4 @@ -use std::io::Write; -use std::path::PathBuf; +use std::{io::Write, path::PathBuf}; // ## lib_name: "protobufd" // ## dir: "..../api_circuits/target/debug/build/lib-circuits-wrapper-49025516ce40925e/out/build/_deps/protobuf_fetch-build" diff --git a/crates/tabby-common/src/events.rs b/crates/tabby-common/src/events.rs index 76c3259d7..b4bb1c145 100644 --- a/crates/tabby-common/src/events.rs +++ b/crates/tabby-common/src/events.rs @@ -1,9 +1,12 @@ +use std::{ + fs, + io::{BufWriter, Write}, + sync::Mutex, +}; + use chrono::Utc; use lazy_static::lazy_static; use serde::Serialize; -use std::fs; -use std::io::{BufWriter, Write}; -use std::sync::Mutex; lazy_static! { static ref WRITER: Mutex> = { diff --git a/crates/tabby-common/src/path.rs b/crates/tabby-common/src/path.rs index 67b2e41ce..56c28a0d3 100644 --- a/crates/tabby-common/src/path.rs +++ b/crates/tabby-common/src/path.rs @@ -1,7 +1,4 @@ -use std::cell::Cell; -use std::env; -use std::path::PathBuf; -use std::sync::Mutex; +use std::{cell::Cell, env, path::PathBuf, sync::Mutex}; use lazy_static::lazy_static; diff --git a/crates/tabby-download/src/cache_info.rs b/crates/tabby-download/src/cache_info.rs index 59972c288..27029e590 100644 --- a/crates/tabby-download/src/cache_info.rs +++ b/crates/tabby-download/src/cache_info.rs @@ -1,8 +1,7 @@ +use std::{collections::HashMap, fs, path::Path}; + use anyhow::Result; use serde::{Deserialize, Serialize}; -use std::collections::HashMap; -use std::fs; -use std::path::Path; use tabby_common::path::ModelDir; #[derive(Serialize, Deserialize)] diff --git a/crates/tabby-download/src/lib.rs b/crates/tabby-download/src/lib.rs index 7bdb0548b..f582c90f3 100644 --- a/crates/tabby-download/src/lib.rs +++ b/crates/tabby-download/src/lib.rs @@ -1,16 +1,12 @@ mod cache_info; -use std::cmp; -use std::fs; -use std::io::Write; -use std::path::Path; +use std::{cmp, fs, io::Write, path::Path}; +use cache_info::CacheInfo; use futures_util::StreamExt; use indicatif::{ProgressBar, ProgressStyle}; use tabby_common::path::ModelDir; -use cache_info::CacheInfo; - impl CacheInfo { async fn download(&mut self, model_id: &str, path: &str, prefer_local_file: bool) { // Create url. diff --git a/crates/tabby-scheduler/src/lib.rs b/crates/tabby-scheduler/src/lib.rs index 5bde7e71b..d9bb2e85a 100644 --- a/crates/tabby-scheduler/src/lib.rs +++ b/crates/tabby-scheduler/src/lib.rs @@ -1,7 +1,8 @@ mod repository; -use job_scheduler::{Job, JobScheduler}; use std::time::Duration; + +use job_scheduler::{Job, JobScheduler}; use tracing::info; pub fn scheduler() { diff --git a/crates/tabby-scheduler/src/repository.rs b/crates/tabby-scheduler/src/repository.rs index 22bf362e9..910467af7 100644 --- a/crates/tabby-scheduler/src/repository.rs +++ b/crates/tabby-scheduler/src/repository.rs @@ -1,13 +1,11 @@ -use std::path::PathBuf; -use std::process::Command; +use std::{path::PathBuf, process::Command}; +use filenamify::filenamify; use tabby_common::{ config::{Config, Repository}, path::repositories_dir, }; -use filenamify::filenamify; - trait ConfigExt { fn sync_repositories(&self); } @@ -71,11 +69,13 @@ pub fn sync_repositories() { #[cfg(test)] mod tests { - use super::*; + use tabby_common::{ + config::{Config, Repository}, + path::set_tabby_root, + }; use temp_testdir::*; - use tabby_common::config::{Config, Repository}; - use tabby_common::path::set_tabby_root; + use super::*; #[test] fn it_works() { diff --git a/crates/tabby/src/serve/completions.rs b/crates/tabby/src/serve/completions.rs index bcff23d59..49af6d04e 100644 --- a/crates/tabby/src/serve/completions.rs +++ b/crates/tabby/src/serve/completions.rs @@ -1,10 +1,10 @@ +use std::{path::Path, sync::Arc}; + use axum::{extract::State, Json}; use ctranslate2_bindings::{ TextInferenceEngine, TextInferenceEngineCreateOptionsBuilder, TextInferenceOptionsBuilder, }; use serde::{Deserialize, Serialize}; -use std::path::Path; -use std::sync::Arc; use strfmt::{strfmt, strfmt_builder}; use tabby_common::{events, path::ModelDir}; use utoipa::ToSchema; diff --git a/crates/tabby/src/serve/completions/languages.rs b/crates/tabby/src/serve/completions/languages.rs index 249fb2fdb..004f96427 100644 --- a/crates/tabby/src/serve/completions/languages.rs +++ b/crates/tabby/src/serve/completions/languages.rs @@ -1,6 +1,7 @@ +use std::collections::HashMap; + use lazy_static::lazy_static; use regex::Regex; -use std::collections::HashMap; lazy_static! { static ref DEFAULT: Regex = Regex::new(r"(?m)\n\n").unwrap(); diff --git a/crates/tabby/src/serve/mod.rs b/crates/tabby/src/serve/mod.rs index 4eeede2d6..81b8da794 100644 --- a/crates/tabby/src/serve/mod.rs +++ b/crates/tabby/src/serve/mod.rs @@ -2,18 +2,20 @@ mod admin; mod completions; mod events; -use crate::Cli; -use axum::{routing, Router, Server}; -use clap::{error::ErrorKind, Args, CommandFactory}; use std::{ net::{Ipv4Addr, SocketAddr}, sync::Arc, }; + +use axum::{routing, Router, Server}; +use clap::{error::ErrorKind, Args, CommandFactory}; use tower_http::cors::CorsLayer; use tracing::info; use utoipa::OpenApi; use utoipa_swagger_ui::SwaggerUi; +use crate::Cli; + #[derive(OpenApi)] #[openapi( paths(events::log_event, completions::completion,),