Skip to content

feat: accept TryInto<KeyExpr> in SampleBuilder::put and ::delete#2508

Open
varunkamath wants to merge 1 commit into
eclipse-zenoh:mainfrom
varunkamath:fix/sample-builder-try-into-keyexpr
Open

feat: accept TryInto<KeyExpr> in SampleBuilder::put and ::delete#2508
varunkamath wants to merge 1 commit into
eclipse-zenoh:mainfrom
varunkamath:fix/sample-builder-try-into-keyexpr

Conversation

@varunkamath

@varunkamath varunkamath commented Mar 21, 2026

Copy link
Copy Markdown

Description

What does this PR do?

Changes SampleBuilder::put and SampleBuilder::delete to accept TryInto<KeyExpr<'static>> instead of Into<KeyExpr<'static>>, so &str can be used directly:

// Before (required manual conversion):
let sample = SampleBuilder::put(KeyExpr::try_from("foo/bar").unwrap(), "payload").into();

// After (just works):
let sample: Sample = SampleBuilder::put("foo/bar", "payload").into();

Why is this change needed?

The current API is unnecessarily restrictive. Other SampleBuilder constructors already accept fallible conversions, and requiring users to manually convert &strKeyExpr is inconvenient. This is a non-breaking change since Into<T> implies TryInto<T>, so all existing call sites continue to compile.

Related Issues

Fixes #2172


🏷️ Label-Based Checklist

No specific label requirements detected.

Current labels: No labels

Add one of these labels to this PR to see relevant checklist items: api-sync, breaking-change, bug, ci, dependencies, documentation, enhancement, new feature, internal

This section updates automatically when labels change.

`SampleBuilder::put` and `SampleBuilder::delete` now accept
`TryInto<KeyExpr<'static>>` instead of `Into<KeyExpr<'static>>`,
allowing `&str` to be passed directly without manual conversion.

This is a non-breaking change: existing code using `Into<KeyExpr>` types
continues to work since `Into<T>` implies `TryInto<T>`.

Fixes eclipse-zenoh#2172

Signed-off-by: Varun Kamath <varunkamath@gmail.com>
Signed-off-by: Varun Kamath <varun.kamath@gmail.com>
@fuzzypixelz fuzzypixelz added the enhancement Existing things could work better label Mar 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Existing things could work better

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SampleBuilder should accept TryFromKeyexpr

2 participants