Refac borrowless client#3
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces significant improvements to the
libft-apiRust 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:
README.mdwith clear features, installation instructions, usage examples, API coverage, contribution guidelines, and project structure overview. [1] [2]API_Structure_Relationships.mdwith a Mermaid diagram and detailed architectural explanation of the API client structure and relationships.Procedural Macro and Code Generation:
libft-api-derivecrate, providing aHasVectorderive macro that automatically implements theHasVectrait for structs with a singleVec<T>field, reducing boilerplate in API response types. [1] [2]Project Structure and Examples:
scrollexample that demonstrates concurrent user retrieval and JSON output, and registered it as a Cargo example. [1] [2]pub modstatements and re-exports, with improved documentation for each endpoint group. [1] [2]Dependency and Maintenance Updates:
serde,tokio,reqwest, and others.Most Important Changes
Documentation and Developer Experience
README.mdwith usage, API coverage, contributing guidelines, and project structure, making the library much more approachable for new users and contributors. [1] [2]API_Structure_Relationships.mdwith a Mermaid diagram and architectural explanations to clarify the relationships between core API client components.Procedural Macros and Code Generation
libft-api-derivecrate with aHasVectorderive macro to automatically implement theHasVectrait for response structs, reducing manual code and potential errors. [1] [2]Examples and Project Structure
scrollexample demonstrating concurrent API usage and JSON export. [1] [2]Dependency Updates
serde,tokio,reqwest, and others to their latest versions for better performance and compatibility.