Skip to content
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

fea/api ergonomics #20

Merged
merged 4 commits into from
Oct 14, 2024
Merged

fea/api ergonomics #20

merged 4 commits into from
Oct 14, 2024

Conversation

mimir-d
Copy link
Contributor

@mimir-d mimir-d commented Oct 12, 2024

This PR fixes a couple of crate api ergonomics issues:

  • resolve the typestate scope in a different way
    • context: end() methods need to consume self so that the user must
      not use the contextual object after having emitted the end artifact.
      However, this introduces an issue in scope() methods, in that we
      need to pass the run object both to the async lambda and to call end,
      which forces the lambda to capture by reference. We cannot move into
      the lambda because we need to consume self in end(), so the lambda
      must receive a reference. This leads to needing to use a boxed future,
      because rust syntax doesn't have a way to specify captured lifetimes
      in async anon.
    • since end() is the only contentious method, make a new type
      ScopedTestRun which has everything except end and pass that with
      lifetime 'static into the lambda. This removes the need for the boxed
      future since no shorter refs are captured.
  • remove the boilerplate needed for tv::Value
    • this commit adds template args such that the users dont need to
      manually covert their values into tv::Value
    • applies for measurements, metadata and run start params

@mimir-d mimir-d requested a review from njordr October 12, 2024 13:42
@mimir-d mimir-d self-assigned this Oct 12, 2024
/// # Ok::<(), OcptvError>(())
/// # });
/// ```
pub async fn add_extension<S: serde::Serialize>(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just moved

Copy link

codecov bot commented Oct 12, 2024

Codecov Report

Attention: Patch coverage is 97.01493% with 4 lines in your changes missing coverage. Please review.

Project coverage is 98.4%. Comparing base (5bc858c) to head (31e0e8d).
Report is 5 commits behind head on dev.

Files with missing lines Patch % Lines
src/output/measure.rs 96.1% 2 Missing ⚠️
src/output/run.rs 96.8% 1 Missing ⚠️
src/output/step.rs 97.7% 1 Missing ⚠️
Additional details and impacted files

- context: `end()` methods need to consume self so that the user must
  not use the contextual object after having emitted the end artifact.
  However, this introduces an issue in `scope()` methods, in that we
  need to pass the run object both to the async lambda and to call end,
  which forces the lambda to capture by reference. We cannot move into
  the lambda because we need to consume self in `end()`, so the lambda
  must receive a reference. This leads to needing to use a boxed future,
  because rust syntax doesn't have a way to specify captured lifetimes
  in async anon.
- since `end()` is the only contentious method, make a new type
  `ScopedTestRun` which has everything except `end` and pass that with
  lifetime 'static into the lambda. This removes the need for the boxed
  future since no shorter refs are captured.

Signed-off-by: mimir-d <[email protected]>
- similar to previous commit, this removes the dependency on boxed
  futures; remove the cargo dependency as well, and the feature flag

Signed-off-by: mimir-d <[email protected]>
- this commit adds template args such that the users dont need to
  manually covert their values into `tv::Value`
- applies for measurements, metadata and run start params

Signed-off-by: mimir-d <[email protected]>
- fix readme to remove boxed-scopes

Signed-off-by: mimir-d <[email protected]>
@mimir-d mimir-d merged commit a59bc8d into dev Oct 14, 2024
14 checks passed
@mimir-d mimir-d deleted the fea/api_ergonomics branch October 14, 2024 10:07
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.

2 participants