### Install nats-server Source: https://github.com/nats-io/nats.rs/blob/main/CLAUDE.md Installs the `nats-server` binary using Go. ```bash go install github.com/nats-io/nats-server/v2@main ``` -------------------------------- ### CI Examples Check Source: https://github.com/nats-io/nats.rs/blob/main/CLAUDE.md CI command to check the compilation of examples. ```bash cargo check --examples ``` -------------------------------- ### NATS.rs Feature Flag Configuration Source: https://github.com/nats-io/nats.rs/blob/main/CLAUDE.md Example TOML configuration for enabling or disabling various features and subsystems in nats.rs. This includes core functionalities like JetStream, Key-Value store, Object store, Service API, and different crypto backends. ```toml # Default: everything enabled default = ["server_2_10", "server_2_11", "server_2_12", "service", "ring", "jetstream", "nkeys", "crypto", "object-store", "kv", "websockets", "nuid"] # Subsystems (each gates a module) jetstream # JetStream API — pulls in time, serde_nanos, tryhard, base64 kv # Key-Value store (requires jetstream) object-store # Object store (requires jetstream + crypto) service # Service API — pulls in time, serde_nanos # Crypto backends (pick one) ring # Default crypto backend aws-lc-rs # Alternative backend fips # FIPS mode (requires aws-lc-rs) # Other nkeys # NKey authentication nuid # NUID-based ID generation (falls back to rand if disabled) crypto # Encryption support websockets # WebSocket transport experimental # Experimental features # Server version markers (no code, just enable version-specific fields/methods) server_2_10 server_2_11 server_2_12 # Test-only slow_tests # Long-running, time-sensitive tests compatibility_tests # Cross-client compatibility tests ``` -------------------------------- ### Feature-Gated Test Module Source: https://github.com/nats-io/nats.rs/blob/main/CLAUDE.md Example of a test module that is conditionally compiled based on the 'kv' feature flag. ```rust #[cfg(feature = "kv")] mod kv_tests { #[tokio::test] async fn create_bucket() { /* ... */ } } ``` -------------------------------- ### Lint Code Source: https://github.com/nats-io/nats.rs/blob/main/CLAUDE.md Lints the code using clippy, denying all warnings. Includes benches, tests, examples, and all features. ```bash cargo clippy --benches --tests --examples --all-features -- --deny clippy::all ``` -------------------------------- ### Build Project Source: https://github.com/nats-io/nats.rs/blob/main/CLAUDE.md Builds all targets for the project. ```bash cargo build --all-targets ``` -------------------------------- ### CI Docs Build Source: https://github.com/nats-io/nats.rs/blob/main/CLAUDE.md CI command to build documentation without dependencies. ```bash cargo doc --no-deps --all-features ``` -------------------------------- ### Rustfmt Configuration Source: https://github.com/nats-io/nats.rs/blob/main/CLAUDE.md Project's Rustfmt configuration settings. ```toml max_width = 100 reorder_imports = true format_code_in_doc_comments = true ``` -------------------------------- ### Run NATS Server for Tests Source: https://github.com/nats-io/nats.rs/blob/main/CLAUDE.md Launches a basic NATS server instance for testing purposes. Supports connecting with default or custom options, and running a cluster. ```rust use nats_server; #[tokio::test] async fn my_test() { // Basic server let server = nats_server::run_server("tests/configs/jetstream.conf"); let client = async_nats::connect(server.client_url()).await.unwrap(); // With options let client = async_nats::ConnectOptions::new() .event_callback(|event| async move { println!("{event:?}") }) .connect(server.client_url()) .await .unwrap(); // Cluster (3 nodes) let cluster = nats_server::run_cluster("tests/configs/jetstream.conf"); } ``` -------------------------------- ### Check Licenses Source: https://github.com/nats-io/nats.rs/blob/main/CLAUDE.md Checks project licenses using `cargo deny`. ```bash cargo deny check licenses ``` -------------------------------- ### CI Min Versions Check Source: https://github.com/nats-io/nats.rs/blob/main/CLAUDE.md CI command to check minimum versions with locked dependencies. ```bash cargo check --locked --all-features --all-targets (with -Zminimal-versions) ``` -------------------------------- ### CI Platform Test Source: https://github.com/nats-io/nats.rs/blob/main/CLAUDE.md CI requirement to test on multiple platforms: Ubuntu, macOS, Windows. ```bash Platforms : Ubuntu, macOS, Windows ``` -------------------------------- ### Format Code Source: https://github.com/nats-io/nats.rs/blob/main/CLAUDE.md Formats the code according to project standards. Requires a nightly toolchain. ```bash cargo +nightly fmt ``` -------------------------------- ### License Header Source: https://github.com/nats-io/nats.rs/blob/main/CLAUDE.md Standard license header required for all source files in the project. ```text // Copyright 2020-2023 The NATS Authors // Licensed under the Apache License, Version 2.0 ``` -------------------------------- ### Run Tests Source: https://github.com/nats-io/nats.rs/blob/main/CLAUDE.md Runs standard tests, requiring the `nats-server` binary in the PATH. Enables `slow_tests` and `websockets` features. ```bash cargo test --features slow_tests,websockets -- --nocapture ``` -------------------------------- ### NATS.rs Project Layering Diagram Source: https://github.com/nats-io/nats.rs/blob/main/README.md Illustrates the relationship between application code, Orbit crates, async-nats (core), and nats-server. Orbit crates depend on async-nats, which interfaces with nats-server. ```text ┌──────────────────────────────────────────────────────┐ │ Application code │ └──────────────┬───────────────────────────┬───────────┘ │ │ ▼ ▼ ┌───────────────────┐ ┌───────────────────┐ │ Orbit crates │ uses │ async-nats (core) │ │ (opinionated, │──────▶│ (parity, stable, │ │ per-crate semver)│ │ protocol-level) │ └───────────────────┘ └─────────┬─────────┘ │ ▼ ┌─────────────┐ │ nats-server │ └─────────────┘ ``` -------------------------------- ### CI Format Check Source: https://github.com/nats-io/nats.rs/blob/main/CLAUDE.md CI command to check code formatting. ```bash cargo +nightly fmt -- --check ``` -------------------------------- ### CI Test Execution Source: https://github.com/nats-io/nats.rs/blob/main/CLAUDE.md CI command to run standard tests with specific features enabled. ```bash cargo test --features slow_tests,websockets ``` -------------------------------- ### Conditional Compilation with Feature Flags in Rust Source: https://github.com/nats-io/nats.rs/blob/main/CLAUDE.md Demonstrates the standard pattern for gating Rust code with feature flags using `#[cfg]` and `#[cfg_attr]` attributes. This ensures that code is only compiled when the specified feature is enabled, and provides documentation hints for `docs.rs`. ```rust #[cfg(feature = "jetstream")] #[cfg_attr(docsrs, doc(cfg(feature = "jetstream")))] pub mod jetstream; ``` -------------------------------- ### CI MSRV Check Source: https://github.com/nats-io/nats.rs/blob/main/CLAUDE.md CI command to check build with the Minimum Supported Rust Version (MSRV). ```bash Build with Rust 1.88.0 ``` -------------------------------- ### CI TLS Backends Test Source: https://github.com/nats-io/nats.rs/blob/main/CLAUDE.md CI requirement to test with different TLS backends (ring, aws-lc-rs, fips). ```bash Tests run separately with `ring`, `aws-lc-rs`, and `fips` ``` -------------------------------- ### CI Environment RUSTFLAGS Source: https://github.com/nats-io/nats.rs/blob/main/CLAUDE.md CI environment setting for RUSTFLAGS, treating all warnings as errors. ```bash RUSTFLAGS="-D warnings" ``` -------------------------------- ### Asserting Publish Errors Source: https://github.com/nats-io/nats.rs/blob/main/CLAUDE.md Demonstrates how to assert specific error kinds when a publish operation fails, such as with a bad subject. ```rust let err = client.publish("bad subject", "".into()).await.unwrap_err(); assert_eq!(err.kind(), PublishErrorKind::BadSubject); ``` -------------------------------- ### Check MSRV Source: https://github.com/nats-io/nats.rs/blob/main/CLAUDE.md Checks the Minimum Supported Rust Version (MSRV) of 1.88.0. ```bash cargo +1.88.0 check ``` -------------------------------- ### Test Specific TLS Backend Source: https://github.com/nats-io/nats.rs/blob/main/CLAUDE.md Tests with a specific TLS backend, disabling default features and enabling various others including JetStream, KV, and crypto. ```bash cargo test tls --no-default-features \ --features jetstream,kv,object-store,service,nkeys,nuid,crypto,websockets,ring ``` -------------------------------- ### NATS.rs Client-Server Communication Flow Source: https://github.com/nats-io/nats.rs/blob/main/CLAUDE.md Illustrates the internal communication path within the nats.rs client, from user commands to the NATS server. The Client handle sends commands via an mpsc channel to the ConnectionHandler, which manages subscriptions and drives reconnection. Protocol I/O is handled by the Connection struct. ```text Client (cloneable handle) │ sends Command variants via mpsc channel ▼ ConnectionHandler (single task) │ manages subscriptions, multiplexer, ping/pong │ drives reconnection via Connector ▼ Connection (protocol I/O) │ read_buf (BytesMut) / write_buf (VecDeque) │ parses ServerOp, serializes ClientOp ▼ NATS Server (TCP / TLS / WebSocket) ``` -------------------------------- ### NATS.rs Generic Error Handling Pattern Source: https://github.com/nats-io/nats.rs/blob/main/CLAUDE.md Illustrates the recommended error handling strategy in nats.rs, utilizing a generic `Error` type. This involves defining a specific `ErrorKind` enum for each subsystem, creating type aliases for convenience, and constructing/matching errors according to the defined pattern. ```rust // 1. Define the kind enum #[derive(Clone, Debug, PartialEq)] pub enum FooErrorKind { NotFound, TimedOut, Other, } impl Display for FooErrorKind { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { Self::NotFound => write!(f, "not found"), Self::TimedOut => write!(f, "timed out"), Self::Other => write!(f, "unknown error"), } } } // 2. Define the error type alias pub type FooError = Error; // 3. Construct errors FooError::new(FooErrorKind::NotFound) FooError::with_source(FooErrorKind::TimedOut, source_error) // 4. Match on errors match result { Err(err) if err.kind() == FooErrorKind::NotFound => { /* handle */ } Err(err) => return Err(err.into()), Ok(val) => val, } ``` -------------------------------- ### CI Spelling Check Source: https://github.com/nats-io/nats.rs/blob/main/CLAUDE.md CI command to perform a spell check on the code. ```bash cargo spellcheck --code 1 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.