nats.rs
nats.rs copied to clipboard
Introduce a `Subject` type to async-nats
Following #222 this introduces the subject type to the new asnyc-nats
client. It seemed to me that async-nats
is now mature enough to bring this in again 😄
I adapted the contents to the new async API. BTW great work the new crates feels much better to work with!
Current state of the PR
At the moment I only tackled the main crate, unit and doc tests to give a feeling for the change. I also have the feeling that I missed some points in the jetstream area where names should be subjects or not.
Next steps
I'll leave the PR in this state until further notice if you want this in the crate I gladly will finish the work to be done.
Don't feel pressured to react to this PR immediately. I just need this for my own project to dive into procedural macros.
My goal is to provide derive macros for The ToSubject
and FromSubject
traits so something like this will be possible:
#[derive(Debug, ToSubject)]
#[subject("my.[ adj ].api.thingy.[ id ]")]
struct ThingApi {
adj: String,
id: u32,
}
fn main() {
let thing = ThingApi {
adj: "awesome".to_string(),
id: 42,
};
assert_eq!(thing.to_subject().unwrap(), subject!("my.awesome.api.thingy.42").unwrap());
}
My progress can be tracked in my forked repo: https://github.com/MattesWhite/nats.rs/pull/2
@MattesWhite I will revisit this PR when done with KV :)