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

Simplify async doc examples #912

Open
clux opened this issue May 14, 2022 · 0 comments
Open

Simplify async doc examples #912

clux opened this issue May 14, 2022 · 0 comments
Labels
docs unclear documentation good first issue Good for newcomers help wanted Not immediately prioritised, please help!

Comments

@clux
Copy link
Member

clux commented May 14, 2022

There are two patterns we use in our docs at the moment:

    /// ```no_run
    /// use kube::{Api, Client};
    /// use k8s_openapi::api::core::v1::Pod;
    /// #[tokio::main]
    /// async fn main() -> Result<(), Box<dyn std::error::Error>> {
    ///     let client = Client::try_default().await?;
    ///     let pods: Api<Pod> = Api::namespaced(client, "apps");
    ///     let p: Pod = pods.get("blog").await?;
    ///     Ok(())
    /// }
    /// ```

e.g. kube-client/src/api/core_methods.rs

/// # async fn wrapper() -> Result<(), Box<dyn std::error::Error>> {
/// some_uncommented_async_operation().await?;
/// # Ok(())
/// # }

e.g. kube-runtime/src/events.rs

The first leads to the full async-setup visible in every example (via e.g. Api docs), and the second leads to business-action only (e.g. via EventRecorder docs)

We should align api docs so that we use the second pattern where possible. Comment out hidden imports, comment out the async wrappers. Deindent.

If we are documenting in kube_runtime we can also use more of the /// # let client: kube::Client = todo!(); pattern to focus on what the crate is about, not what kube_client is about.

To find places to replace search within the crates:

$ rg "tokio::main" kube-runtime
kube-runtime/src/controller/mod.rs
517:/// #[tokio::main]

kube-runtime/src/watcher.rs
692:/// #[tokio::main]
755:/// #[tokio::main]

affected crates:

  • kube-runtime
  • kube-client
  • kube

(the ones in examples/e2e/readmes should be left in place)

@clux clux added help wanted Not immediately prioritised, please help! docs unclear documentation labels May 14, 2022
@clux clux removed the help wanted Not immediately prioritised, please help! label Mar 5, 2023
@clux clux self-assigned this Mar 5, 2023
@clux clux added help wanted Not immediately prioritised, please help! good first issue Good for newcomers labels Sep 13, 2023
@clux clux removed their assignment Sep 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs unclear documentation good first issue Good for newcomers help wanted Not immediately prioritised, please help!
Projects
Status: Backlog
Development

No branches or pull requests

1 participant