I suggest the feature was requested for tens of times before me. But I couldn't find it in the Bugzilla. RSync as the protocol may be useful to many other applications. There even is a librsync (https://github.com/librsync/librsync) which is used by a few applications, yet that librsync is incompatible with this rsync Do you think it's possible to create an API and extract the library out of the rsync code?
I asked exactly this 10 years ago to the mailing list. The answer was no. This is not a simple to do. You could do it, I decided that kind of project would move me too far away from what I actually wanted to achieve. I went instead for calling rsync from a daemon and handing data via pipes. ( https://github.com/axkibe/lsyncd ). You just need some process management.