-
-
Notifications
You must be signed in to change notification settings - Fork 488
Add generic immutable interface. #433
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Add a GenericClient trait over Client and Transaction, and replace &mut with &.
The methods should take |
Could you explain that? It wasn't like this in the previous versions. Is this because of tokio? In the old version I was using |
Internal mutability is very rare in Rust APIs. It only existed in this library because of an old, pre-Rust 1.0 API design that was overhauled significantly in the latest release. If you want to use internal mutability in your code, you can use a RefCell as you've noted, but a connection pool like r2d2 is possibly a more appropriate choice. |
r2d2 uses an Arc which is little heavy for what I need. |
What percentage of your runtime has your profiling indicated is spent in Arc code? |
It's a discord/twitch clone (weird I know), but if users are spamming I don't want a ton of Arc locks. I'm using Actix websockets, which are sorta-kinda single-threaded from what I understand. |
That wasn't really an answer to my question. |
I haven't profiled this app, but in a previous experience with Arcs it was pretty bad locking for every request when you have a large number of messages. |
Arcs are used in proximity to all kinds of high performance code (and an Arc is not a lock in the first place). I'm not interested in adding a bunch of internal mutability back to this crate. |
What about a GenericClient trait? |
Sure, I'd be happy to add that trait back. |
And you're right, I was thinking of |
@sfackler did you ever look at bringing back the GenericConnection trait into the newer versions? |
Ah, I have not yet but it seems reasonable to do! |
@sfackler was there a specific change or re-architecture that prompted its removal? Just wanting to make sure there wasn't a better way to handle that need that I was missing. |
The crate was rewritten from scratch, and the trait just never made it back in. |
I added a GenericClient trait over Client and Transaction, and replaced &mut with & to support the same style of trait as in previous versions.
I'm using GenericConnection in the old versions and I just wanted to try to add it back. I just named it GenericClient to match the new Client struct.
Thoughts?
Related issue:
#329