Skip to content

add documentation on pre and post hooks to builder methods #934

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions progenitor-impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,24 +137,46 @@ impl GenerationSettings {
}

/// Hook invoked before issuing the HTTP request.
/// The signature for the pre hook function should be either
/// * `pre_hook(&request::Client) -> ()` without an inner type, or
/// * `pre_hook(&InnerType, &request::Client) -> ()`
/// if an inner type was specified using [`with_inner_type()`](Self::with_inner_type).
pub fn with_pre_hook(&mut self, pre_hook: TokenStream) -> &mut Self {
self.pre_hook = Some(pre_hook);
self
}

/// Hook invoked before issuing the HTTP request.
/// The signature for the pre hook function should be either
/// * `async pre_hook(&mut request::Client) -> Result<_,E>` without an inner type, or
/// * `async pre_hook(&InnerType, &mut request::Client) -> Result<_,E>`
/// if an inner type was specified using [`with_inner_type()`](Self::with_inner_type).
///
/// Returning an error result will abort the call with
/// an `Error::PreHookError` (type declared in generated code).
pub fn with_pre_hook_async(&mut self, pre_hook: TokenStream) -> &mut Self {
self.pre_hook_async = Some(pre_hook);
self
}

/// Hook invoked prior to receiving the HTTP response.
/// The signature for the post hook function should be either
/// * `post_hook(&Result<reqwest::Response,reqwest::Error>) -> ()` without an inner type, or
/// * `post_hook(&InnerType, &Result<reqwest::Response,reqwest::Error>) -> ()`
/// if an inner type was specified using [`with_inner_type()`](Self::with_inner_type).
pub fn with_post_hook(&mut self, post_hook: TokenStream) -> &mut Self {
self.post_hook = Some(post_hook);
self
}

/// Hook invoked prior to receiving the HTTP response.
/// The signature for the post hook function should be either
/// * `async post_hook(&Result<reqwest::Response,reqwest::Error>) -> ()` without an innter type, or
/// * `async post_hook(&InnerType, &Result<reqwest::Response,reqwest::Error>) -> Result<_,E>`
/// if an inner type was specified using [`with_inner_type()`](Self::with_inner_type).
///
/// Returning an error result will abort the call with
/// an `Error::PostHookError` (type declared in generated code).
pub fn with_post_hook_async(&mut self, post_hook: TokenStream) -> &mut Self {
self.post_hook_async = Some(post_hook);
self
Expand Down