davidMcneil / rants

An async NATS client library for the Rust programming language.
Apache License 2.0
81 stars 11 forks source link

Allow getting subject name #14

Closed nevi-me closed 4 years ago

nevi-me commented 4 years ago

I noticed that I can't retrieve the name of a Subject. If I subscribe to a wildcard/prefix subject such as notifications.>, I want to be able to inspect which subject I received (e.g. notifications.emergency.accident, and react to it accordingly.

It looks like the only thing I can do is use Display.

davidMcneil commented 4 years ago

Thank you for taking the time to open an issue.

I am not sure I fully follow what you are trying to accomplish. Would you mind posting code showing what methods would be useful to have added to the library?

If you want the string representation of a Subject you can use to_string. If you want to get the Subject of a recieved message you can use the subject method.

I could see it being useful to have a matches (or something like that) method on Subject that checks if one Subject is matched by another Subject's wildcards. Is that what you are getting at?

nevi-me commented 4 years ago

My apologies, I hadn't seen that ToString is implemented on Subject. I'm sorted now, happy new year!

baadc0de commented 4 years ago

I'd like to comment that it would be great to have access to the tokens that make up the subject. For example when subscribing to a.*.status rants already has the middle wildcard value populated in the tokens field. Getting that directly instead of going to_string seems like a good thing to me.