// Copyright 2024 RustFS Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#![recursion_limit = "256"]

//! RustFS — high-performance S3-compatible object storage.
//!
//! This library exposes the [`embedded`] module which lets you start a
//! fully-functional RustFS server **in-process** — ideal for integration
//! tests that need a local S3 endpoint without Docker or child processes.
//!
//! # Quick start
//!
//! ```rust,no_run
//! use rustfs::embedded::{find_available_port, RustFSServerBuilder};
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
//!     let port = find_available_port()?;
//!     let server = RustFSServerBuilder::new()
//!         .address(format!("127.0.0.1:{port}"))
//!         .access_key("minioadmin")
//!         .secret_key("minioadmin")
//!         .build()
//!         .await?;
//!
//!     println!("S3 endpoint: {}", server.endpoint());
//!
//!     // ... use any S3 client against server.endpoint() ...
//!
//!     server.shutdown().await;
//!     Ok(())
//! }
//! ```
//!
//! # Limitations
//!
//! Because the underlying storage engine uses process-global singletons,
//! **only one `RustFSServer` may exist per process**. Attempting to start
//! a second server will return an error. This is fine for integration
//! tests where you start one server in a background task, run all your
//! tests, and then shut it down.

/// Scope-based hotpath measurement for `#[async_trait]` methods, where
/// `#[hotpath::measure]` would only time the boxed-future construction.
/// The guard records wall time from this statement until the enclosing
/// (desugared) async block completes, including early returns via `?`.
/// With the `hotpath` feature off it expands to nothing.
#[cfg(feature = "hotpath")]
#[macro_export]
macro_rules! hp_guard {
    ($label:expr) => {
        let _hotpath_scope_guard = ::hotpath::functions::build_measurement_guard_sync($label, false);
    };
}

#[cfg(not(feature = "hotpath"))]
#[macro_export]
macro_rules! hp_guard {
    ($label:expr) => {};
}

pub mod admin;
pub mod allocator_reclaim;
pub mod app;
pub mod auth;
pub mod auth_keystone;
pub(crate) mod bitrot_selftest;
pub mod capacity;
pub mod cgroup_resources;
pub mod cluster_snapshot;
pub mod config;
pub mod connect;
pub mod delete_tail_activity;
pub mod diagnose;
pub mod embedded;
pub mod error;
pub mod init;
pub mod inspect;
pub(crate) mod kms_deletion_gate;
pub(crate) mod kms_rekey;
pub mod license;
pub mod memory_observability;
pub mod module_switches;
pub mod on_demand_migration;
pub mod profiling;
#[cfg(any(feature = "ftps", feature = "webdav", feature = "sftp"))]
pub mod protocols;
pub mod runtime_capabilities;
pub(crate) mod runtime_sources;
pub mod server;
pub mod shared_types;
pub(crate) mod site_replication;
pub(crate) mod site_replication_reconcile;
pub(crate) mod startup_audit;
pub(crate) mod startup_auth;
pub(crate) mod startup_background;
pub(crate) mod startup_bucket_metadata;
pub(crate) mod startup_deadlock;
pub(crate) mod startup_embedded;
pub(crate) mod startup_embedded_optional;
pub mod startup_entrypoint;
pub(crate) mod startup_fs_guard;
pub(crate) mod startup_iam;
pub(crate) mod startup_lifecycle;
pub(crate) mod startup_notification;
pub(crate) mod startup_observability;
pub(crate) mod startup_optional_runtime_sidecars;
pub(crate) mod startup_preflight;
pub(crate) mod startup_protocols;
pub(crate) mod startup_runtime;
pub(crate) mod startup_runtime_hooks;
pub(crate) mod startup_runtime_sources;
pub(crate) mod startup_server;
pub(crate) mod startup_services;
pub(crate) mod startup_shutdown;
pub(crate) mod startup_storage;
pub(crate) mod startup_tls_material;
pub mod storage;
pub(crate) mod storage_api;
pub(crate) mod table_catalog;
pub mod tls;
pub mod update;
pub mod version;
pub mod workload_admission;

// Re-export from rustfs_utils so that config sub-modules can use
// `crate::apply_external_env_compat` without breaking.
pub use rustfs_utils::{ExternalEnvCompatReport, apply_external_env_compat};
