Skip to content

Refac borrowless client#3

Merged
hdoo42 merged 18 commits into
masterfrom
refac-borrowless_client
Oct 14, 2025
Merged

Refac borrowless client#3
hdoo42 merged 18 commits into
masterfrom
refac-borrowless_client

Conversation

@hdoo42

@hdoo42 hdoo42 commented Oct 14, 2025

Copy link
Copy Markdown
Owner

This pull request introduces significant improvements to the libft-api Rust library, focusing on enhanced documentation, a new procedural macro for reducing boilerplate, improved project structure, and updated dependencies. The changes make the library easier to use, extend, and contribute to, while providing clearer guidance and better ergonomics for end users.

Documentation and API Usability Improvements:

  • Added a comprehensive README.md with clear features, installation instructions, usage examples, API coverage, contribution guidelines, and project structure overview. [1] [2]
  • Introduced API_Structure_Relationships.md with a Mermaid diagram and detailed architectural explanation of the API client structure and relationships.
  • All API modules now include Rustdoc comments and usage examples, making it easier for developers to understand and use the endpoints. [1] [2]

Procedural Macro and Code Generation:

  • Added the libft-api-derive crate, providing a HasVector derive macro that automatically implements the HasVec trait for structs with a single Vec<T> field, reducing boilerplate in API response types. [1] [2]
  • Integrated the new derive macro into the main crate's dependencies.

Project Structure and Examples:

  • Refactored the examples: replaced multiple binaries with a single scroll example that demonstrates concurrent user retrieval and JSON output, and registered it as a Cargo example. [1] [2]
  • Updated the API module structure to use explicit pub mod statements and re-exports, with improved documentation for each endpoint group. [1] [2]

Dependency and Maintenance Updates:

  • Updated several dependencies to their latest versions for improved security and performance, including serde, tokio, reqwest, and others.

Most Important Changes

Documentation and Developer Experience

  • Added a detailed README.md with usage, API coverage, contributing guidelines, and project structure, making the library much more approachable for new users and contributors. [1] [2]
  • Added API_Structure_Relationships.md with a Mermaid diagram and architectural explanations to clarify the relationships between core API client components.
  • Enhanced Rustdoc comments and usage examples for all API modules and endpoints, improving discoverability and usability. [1] [2]

Procedural Macros and Code Generation

  • Introduced the libft-api-derive crate with a HasVector derive macro to automatically implement the HasVec trait for response structs, reducing manual code and potential errors. [1] [2]
  • Integrated the derive macro into the main crate, enabling its use in API response types.

Examples and Project Structure

  • Consolidated multiple binaries into a single, well-documented scroll example demonstrating concurrent API usage and JSON export. [1] [2]
  • Improved module organization and visibility, making it easier to extend and maintain the codebase. [1] [2]

Dependency Updates

  • Updated dependencies such as serde, tokio, reqwest, and others to their latest versions for better performance and compatibility.

hdoo42 added 18 commits October 4, 2025 17:19
The `FtClientSession` no longer borrows the `FtApiToken`, but instead takes ownership of it. This simplifies the API by removing the lifetime parameter `'a` from `FtClientSession` and its related `impl` blocks.

This change makes it easier to work with sessions, especially in asynchronous contexts where managing lifetimes can be complex. All method calls have been updated to reflect this new ownership model.

BREAKING CHANGE: The signature of `FtClient::open_session` has changed from `open_session<'a>(&'a self, token: &'a FtApiToken) -> FtClientSession<'a, FCHC>` to `open_session(&self, token: FtApiToken) -> FtClientSession<'_, FCHC>`. Consumers of the library must now pass the `FtApiToken` by value.
Replaced `panic!` with `syn::Error` in the `HasVector` procedural macro to provide more descriptive and well-located compile-time errors.

The macro will now emit specific errors if the derive is used on non-struct types, structs without named fields, or structs that do not contain exactly one `Vec<T>` field. This improves the developer experience by providing clear feedback instead of a macro panic.
This commit introduces a `HasVector` derive macro to automatically implement the `HasVec` trait for API response structs. This significantly reduces boilerplate code by removing the need for manual implementations across numerous response types.

Key changes include:
- Creation and application of the `HasVector` derive macro.
- Removal of manual `HasVec` trait implementations.
- Consolidation of common imports into a `prelude` module for cleaner code.
- Introduction of a `QueryParam` type alias to simplify function signatures in `common/param.rs`.

BREAKING CHANGE: The `AccessTokenScope` enum has been removed from the public API as it was unused.
This commit completely refactors the `RateLimiter` to improve its correctness, performance, and testability.

The previous implementation used multiple `Arc<Mutex<T>>` for each state variable, leading to complex locking logic within the `acquire` loop. This could cause contention and made reasoning about the state difficult.

The new design consolidates all state into a single `Inner` struct protected by one `Arc<Mutex<Inner>>`. The `acquire` method now uses a short-lived lock to decide on an action (Permit, Sleep, or Recheck) and performs any waiting *outside* the lock, preventing long-held locks.

Key changes:
- Replaced multiple mutexes with a single mutex over a state struct.
- Switched from `SystemTime` to monotonic `tokio::time::Instant` for duration calculations.
- Redesigned `acquire` to separate decision-making (under lock) from waiting (outside lock).
- Rewrote all tests to use `tokio::time::pause()` and `advance()` for deterministic, reliable execution without real-time delays.
- Added comprehensive tests for concurrency, header updates, and edge cases like `retry-after`.
This commit refactors the client and authentication flow to improve ergonomics and performance.

A token caching mechanism has been introduced via `FtApiToken::try_get`. This function attempts to retrieve a valid token from a temporary file, falling back to fetching a new one if the cached token is invalid or non-existent. This reduces the number of authentication requests.

The `journals.rs` example binary has been updated to use a new `scroller` utility, simplifying pagination logic.

Additionally, extensive documentation has been added across the `auth`, `client`, and `connector` modules to improve developer experience.

BREAKING CHANGE: The `page` field in `FtApiCampusIdJournalsRequest` has been changed from `Option<u16>` to `Option<usize>` to support a larger number of pages.
This commit introduces a major refactoring of the `libft-api` crate to improve its structure, ergonomics, and maintainability.

Key changes include:
- Reorganized the module hierarchy into distinct `api`, `models`, `auth`, `common`, `connector`, and `info` modules.
- Introduced top-level and model-specific preludes for easier imports.
- Migrated all binaries from the `bin/` directory to `examples/`, converting them to library examples.
- Replaced `FtApiToken::build` with `FtApiToken::try_get` for consistent error handling.
- Added crate-level documentation to `lib.rs` explaining the new structure and usage.
- Cleaned up dependencies and `use` statements across the codebase.

BREAKING CHANGE:
- The entire public API surface has been reorganized. Module paths for most types and functions have changed. Users will need to update their `use` statements.
- Binaries are no longer available via `cargo install`. They must now be run as examples using `cargo run --example <name>`.
- `FtApiToken::build` has been removed in favor of `FtApiToken::try_get`.
- The type of `FtProjectSessionId` has been changed from `i16` to `u16`.
This commit introduces several refactoring changes to the `libft-api` crate to simplify its internal structure and improve code quality.

The `FtClientApiCallContext` struct has been removed from the `connector` module. This simplifies the API call process by removing the need to pass around context, contributing to a "borrow-less" design.

Additionally, wildcard imports (`use crate::*;`) have been removed from test modules in favor of more specific imports. Unused imports have also been cleaned up across various files. The API submodules are now explicitly made public for better library structure.
The result of the API call in the `users_id_correction_points_add` test is now ignored to fix an unused variable warning.

Additionally, the `unexpected_cfgs` lint is allowed at the crate level to address warnings related to conditional compilation configurations.
This commit introduces a major overhaul of the project's documentation and refines the public API.

The README.md has been completely rewritten to provide a comprehensive guide for new users, including sections on features, installation, usage examples, API status, project structure, and contribution guidelines.

Extensive rustdoc comments have been added to the `auth.rs` and `lib.rs` modules to improve inline documentation and auto-generated docs.

The `auth` module is now public, allowing users to directly interact with authentication types like `AuthInfo` for more flexible credential management. The main library documentation has been updated to reflect the current module structure.
This commit introduces comprehensive documentation across several key modules of the `libft-api` crate. Module-level explanations, examples, and type-level doc comments have been added to improve usability and developer experience.

The following areas have been updated:
- `api`: Added module overview and `HasVec` trait documentation.
- `common`: Added module overview with an example.
- `connector`: Added module overview explaining its role.
- `models::locations`: Documented location-related data structures.
- `models::user`: Documented user-related data structures.
This commit introduces extensive documentation across the public API of the `libft-api` and `libft-api-derive` crates.

Key changes include:
- Added module-level documentation explaining the purpose of each API endpoint group (e.g., campus, user, project).
- Added detailed doc comments for each public API client method, including descriptions of parameters, return values, and usage examples.
- Documented the `HasVector` procedural macro in `libft-api-derive`.
- Added crate-level and prelude documentation to improve discoverability and usability.

This effort aims to make the library easier to understand and use for developers by providing clear, in-code explanations and examples for all major functionalities.
This commit introduces two main changes:
1.  The `info::campus_id` module is renamed to `info::ft_campus_id` to improve naming consistency across the API.
2.  Comprehensive documentation and usage examples have been added to several API endpoints, including `cursus_id_projects`, `groups`, and `projects`, to enhance developer experience.

BREAKING CHANGE: The `info::campus_id` module has been renamed to `info::ft_campus_id`. Usages of campus ID constants must be updated to the new path.
This commit enhances the public API of the `libft-api` crate.

The `connector` module is now public, enabling users to build their own
HTTP client connectors or extend the existing functionality.

Additionally, comprehensive documentation has been added to the core
client components, including `FtClient`, `FtClientSession`, and related
type aliases. These doc comments include usage examples to improve
the developer experience.
@hdoo42 hdoo42 merged commit aa43e30 into master Oct 14, 2025
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant