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

examples: allow configurable uds socket paths #1613

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

kriswuollett
Copy link

Update unix domain socket examples to show configurable paths. It demonstrates a way of configuring the UDS client using the ustr crate to meet the closure capture requirements of the connector service_fn.

Fixes: #1611
Refs: #1612

Motivation

Share a solution of how to configure a UDS client path at runtime.

Solution

Use the ustr crate to vend a &'static str to the UDS connection building closure.

Update unix domain socket examples to show configurable paths. It
demonstrates a way of configuring the UDS client using the ustr crate to
meet the closure capture requirements of the connector service_fn.

Fixes: hyperium#1611
Refs: hyperium#1612

#[cfg(unix)]
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Path needs to be a static str due to service_fn FnMut.
let path = match env::var("EXAMPLE_UDS_PATH") {
Ok(path) => ustr(path.as_ref()).as_str(),
Copy link
Member

Choose a reason for hiding this comment

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

I want to say converting a path to a string should be possible without a third party crate?

Copy link
Author

Choose a reason for hiding this comment

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

Would something like a OnceLock<String> work? AFAICT a &'static str is required. I used ustr because in an actual application one may have multiple copies of the same client but with different endpoints -- I think you'd end up reimplementing ustr in that case?

Copy link
Author

Choose a reason for hiding this comment

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

Perhaps there is something obvious I missed, but when using a String, and for the reason I filed that other linked issue...

expected a closure that implements the `FnMut` trait, but this closure only implements `FnOnce`
required for `ServiceFn<{closure@examples/src/uds/client.rs:29:44: 29:57}>` to implement `Service<Uri>`
required for `ServiceFn<{closure@examples/src/uds/client.rs:29:44: 29:57}>` to implement `MakeConnection<Uri>`rustc[Click for full compiler diagnostic](rust-analyzer-diagnostics-view:/diagnostic%20message%20%5B3%5D?3#file%3A%2F%2F%2FUsers%2Fkris%2FCode%2Fkriswuollett%2Ftonic%2Fexamples%2Fsrc%2Fuds%2Fclient.rs)
client.rs(29, 10): the requirement to implement `FnMut` derives from here
client.rs(31, 33): closure is `FnOnce` because it moves the variable `path` out of its environment

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.

Update UDS example with socket paths determined at runtime
2 participants