Skip to content

Conversation

@The-Ladle
Copy link

Working with this, I needed to access multiple different topics from the same prefix. While I could have simply used a string for my prefix (which is what I am doing now), I figured it would be more intuitive to add a function that returns a "child" topic. Feel free to change anything about this; I am definitely not the best Rust programmer.

@DatAsianBoi123
Copy link
Owner

That sounds like a valid use-case, though the code doesn't seem to do what you described?

What I interpret a ::child function to do is:

Topic topic = client.topic("/mytopic"); // `/mytopic`
Topic child = topic.child("/suffix"); // `/mytopic/suffix`

But the current implementation that you have only returns a topic with the same name as the argument in ::child.

@DatAsianBoi123
Copy link
Owner

Also, just a nitpick but I recently switched to using conventional commits as a convention for commit messages, so it would be nice to change that one commit message to follow that convention. Something like feat: added Topic::child method that returns a child topic would be great.

@The-Ladle
Copy link
Author

I just realized that I didn't combine the strings 🤦. My bad.

@The-Ladle The-Ladle changed the title Add .child() function to allow topic to act as prefix feat: added Topic::child method that returns a child topic Jul 11, 2025
@The-Ladle
Copy link
Author

I just fixed the issue. Apologies for the error, and thanks for catching it.

@DatAsianBoi123
Copy link
Owner

Alright looks good now, just a couple things before I merge:

  • The method should return Self, right now it returns ()
  • Just for convention's sake, you should be using Self::new instead of Topic::new
  • The method can take just a &str since you don't need an owned String
  • It would be nice to create documentation examples because it may be unclear what the method does

@The-Ladle
Copy link
Author

Thanks for the feedback on the function, as I stated earlier, I'm nowhere near the greatest rust programmer. I assume you're fixing those before merging (with the likely exception of the documentation since that is not crucial)?

@DatAsianBoi123
Copy link
Owner

I don't have permission to as the pr is merging from your own repo that I don't have write access to.

@The-Ladle
Copy link
Author

Ok, I will fix that when I get home and probably write some documentation on what it is for/how to use it.

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.

2 participants