Skip to content

Document client structure#777

Merged
trmartin4 merged 4 commits intomainfrom
platform/document-client-structure
Mar 14, 2026
Merged

Document client structure#777
trmartin4 merged 4 commits intomainfrom
platform/document-client-structure

Conversation

@trmartin4
Copy link
Member

@trmartin4 trmartin4 commented Mar 3, 2026

🎟️ Tracking

https://bitwarden.atlassian.net/browse/PM-30764

📔 Objective

Capture recommended patterns for creating Client implementations in sdk-internal.

Creating a "client" will be required for any new feature crate, so having best practices for how this code is structured feels important. We have several different patterns currently in play in sdk-internal, and this PR attempts to guide future development toward our current best practices and allow us to reference this documentation for guidance.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Mar 3, 2026

Deploying contributing-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 250d8b5
Status: ✅  Deploy successful!
Preview URL: https://05dfce03.contributing-docs.pages.dev
Branch Preview URL: https://platform-document-client-str.contributing-docs.pages.dev

View logs

@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2026

Logo
Checkmarx One – Scan Summary & Detailsc6dd793b-bbef-48ac-a9b5-962ca965c586

Great job! No new security vulnerabilities introduced in this pull request

@trmartin4 trmartin4 marked this pull request as ready for review March 3, 2026 22:37
@trmartin4 trmartin4 requested a review from a team as a code owner March 3, 2026 22:37

:::warning

Avoid the thin passthrough pattern, where the client delegates to free functions defined elsewhere.
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion:

Suggested change
Avoid the thin passthrough pattern, where the client delegates to free functions defined elsewhere.
Avoid the thin passthrough pattern, where the client delegates to pure functions defined elsewhere.

Copy link
Member

Choose a reason for hiding this comment

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

I feel like calling them pure wouldn't be entirely correct, as some of these functions will modify the client's state in some way (think of initialize_user_crypto for example)

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah true, hmm, apparently this is just me being a noob, "free function" is an established term :)

Copy link
Member Author

Choose a reason for hiding this comment

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

I relied on Claude for this part, as I wasn't sure what to call them either, especially in Rust. Would it be clearer to just say "to methods defined elsewhere"?

Copy link
Member

Choose a reason for hiding this comment

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

I think the warning text is clear enough, though I agree that the free/associated function terminology might not be clear for newcomers. Maybe the easiest way would be to include a simple example of what not to do?

impl LoginClient {
    // Avoid delegating the entire implementation to another function like this.
    pub async fn login_with_password(&self, data: LoginData) -> Result<()> {
        login_with_password(self.client, data).await
    } 
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Added this example in b560004 (this PR).

@trmartin4 trmartin4 requested review from coroiu and dani-garcia March 4, 2026 18:23
coroiu
coroiu previously approved these changes Mar 5, 2026
Copy link
Contributor

@coroiu coroiu left a comment

Choose a reason for hiding this comment

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

I agree with Danis suggestion with the example, all good otherwise

├── mod.rs
└── method_name/
├── mod.rs
├── method_name_impl.rs # impl DomainClient { fn method_name() } and tests
Copy link
Member

Choose a reason for hiding this comment

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

I don't think it's recommended to name files _impl.

Suggested change
├── method_name_impl.rs # impl DomainClient { fn method_name() } and tests
├── method_name.rs # impl DomainClient { fn method_name() } and tests

Copy link
Member Author

Choose a reason for hiding this comment

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

Addressed in b560004 (this PR)

@trmartin4 trmartin4 requested review from Hinton and coroiu March 12, 2026 16:53
@trmartin4 trmartin4 enabled auto-merge (squash) March 12, 2026 19:26
@trmartin4 trmartin4 disabled auto-merge March 14, 2026 21:43
@trmartin4 trmartin4 removed the request for review from dani-garcia March 14, 2026 21:45
@trmartin4 trmartin4 merged commit ea2b8a2 into main Mar 14, 2026
13 checks passed
@trmartin4 trmartin4 deleted the platform/document-client-structure branch March 14, 2026 21:47
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.

5 participants