Skip to content

Commit

Permalink
codegen: Take &self for subscription functions of proxy types
Browse files Browse the repository at this point in the history
  • Loading branch information
dennis-hamester committed Aug 22, 2024
1 parent d095973 commit f20eff3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions codegen/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add `type_id()` getter to services.
- Add `query_introspection()` to services.

### Changed

- Take `&self` instead of `&mut self` in `subscribe_{event}()`, `unsubscribe_{event}()`,
`subscribe_all()` and `unsubscribe_all()` of proxy types.

## [0.7.0] - 2024-07-25

### Added
Expand Down
8 changes: 4 additions & 4 deletions codegen/src/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ impl<'a> RustGenerator<'a> {
genln!(self);
}

genln!(self, " pub async fn subscribe_all(&mut self) -> Result<(), aldrin::Error> {{");
genln!(self, " pub async fn subscribe_all(&self) -> Result<(), aldrin::Error> {{");
for item in svc.items() {
let ev = match item {
ast::ServiceItem::Event(ev) => ev,
Expand All @@ -914,7 +914,7 @@ impl<'a> RustGenerator<'a> {
genln!(self, " }}");
genln!(self);

genln!(self, " pub async fn unsubscribe_all(&mut self) -> Result<(), aldrin::Error> {{");
genln!(self, " pub async fn unsubscribe_all(&self) -> Result<(), aldrin::Error> {{");
for item in svc.items() {
let ev = match item {
ast::ServiceItem::Event(ev) => ev,
Expand All @@ -936,12 +936,12 @@ impl<'a> RustGenerator<'a> {
let ev_name = ev.name().value();
let id = ev.id().value();

genln!(self, " pub async fn {}(&mut self) -> Result<(), aldrin::Error> {{", subscribe_event(ev_name));
genln!(self, " pub async fn {}(&self) -> Result<(), aldrin::Error> {{", subscribe_event(ev_name));
genln!(self, " self.inner.subscribe({id}).await");
genln!(self, " }}");
genln!(self);

genln!(self, " pub async fn {}(&mut self) -> Result<(), aldrin::Error> {{", unsubscribe_event(ev_name));
genln!(self, " pub async fn {}(&self) -> Result<(), aldrin::Error> {{", unsubscribe_event(ev_name));
genln!(self, " self.inner.unsubscribe({id}).await");
genln!(self, " }}");
genln!(self);
Expand Down

0 comments on commit f20eff3

Please sign in to comment.