Skip to content

Replace trait with enum in Rust#575

Merged
baijumeswani merged 3 commits intocopilot/update-language-bindings-documentationfrom
nebanfic/replace-train-with-enum-rust
Apr 1, 2026
Merged

Replace trait with enum in Rust#575
baijumeswani merged 3 commits intocopilot/update-language-bindings-documentationfrom
nebanfic/replace-train-with-enum-rust

Conversation

@nenad1002
Copy link
Copy Markdown
Contributor

Async methods on traits require [Pin<Box>] return types, which pollute the public API.

Additionally, C# interfaces and Rust traits are not equivalent abstractions, and traits offer no obvious advantage here.

Since the set of implementors is closed and internal, an enum with private variants provides the same polymorphism with a cleaner, more idiomatic Rust API.

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 1, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
foundry-local Ready Ready Preview, Comment Apr 1, 2026 8:59pm

Request Review

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the Rust SDK’s model abstraction by removing the public IModel trait and replacing it with a single public Model type backed by an internal enum, avoiding boxed-future trait method signatures and simplifying the public API surface.

Changes:

  • Removed the public IModel trait and updated the crate exports accordingly.
  • Reworked Model to wrap either a single variant or a grouped multi-variant model via an internal ModelKind enum, exposing async methods directly on Model.
  • Updated Catalog, examples, samples, and integration tests to use Arc<Model> and the new download progress callback shape.

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
sdk/rust/tests/integration/model_test.rs Updates tests to work with Arc<Model> and the new API.
sdk/rust/src/lib.rs Stops exporting IModel / removes imodel module wiring; keeps Model as the public type.
sdk/rust/src/imodel.rs Deletes the public IModel trait entirely.
sdk/rust/src/detail/model.rs Introduces public Model with internal ModelKind enum and async methods on the concrete type.
sdk/rust/src/detail/model_variant.rs Converts variant operations to concrete async methods (no trait impl) and updates docs.
sdk/rust/src/catalog.rs Updates catalog lookups/collections to return Arc<Model> (models and per-id variants).
sdk/rust/examples/tool_calling.rs Updates progress callback usage for download.
sdk/rust/examples/interactive_chat.rs Updates progress callback usage for download.
sdk/rust/examples/chat_completion.rs Updates progress callback usage for download.
samples/rust/tutorial-voice-to-text/src/main.rs Updates progress callback usage for download.
samples/rust/tutorial-tool-calling/src/main.rs Updates progress callback usage for download.
samples/rust/tutorial-document-summarizer/src/main.rs Updates progress callback usage for download.
samples/rust/tutorial-chat-assistant/src/main.rs Updates progress callback usage for download.
samples/rust/tool-calling-foundry-local/src/main.rs Updates progress callback usage for download.
samples/rust/native-chat-completions/src/main.rs Updates progress callback usage for download.
samples/rust/foundry-local-webserver/src/main.rs Updates progress callback usage for download (incl. move closure).
samples/rust/audio-transcription-example/src/main.rs Updates progress callback usage for download.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@baijumeswani baijumeswani marked this pull request as ready for review April 1, 2026 22:39
@baijumeswani baijumeswani merged commit e5851a2 into copilot/update-language-bindings-documentation Apr 1, 2026
38 of 42 checks passed
@baijumeswani baijumeswani deleted the nebanfic/replace-train-with-enum-rust branch April 1, 2026 22:39
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.

3 participants