Skip to content

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

Closed
wants to merge 3 commits into from

Conversation

enzious
Copy link

@enzious enzious commented Apr 8, 2019

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

Add a GenericClient trait over Client and Transaction, and replace &mut with &.
@sfackler
Copy link
Owner

sfackler commented Apr 9, 2019

The methods should take &mut self.

@enzious
Copy link
Author

enzious commented Apr 9, 2019

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 Rc<Connection>, but with this I'll have to use Rc<RefCell<Client>> everywhere.

@sfackler
Copy link
Owner

sfackler commented Apr 9, 2019

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.

@enzious
Copy link
Author

enzious commented Apr 9, 2019

r2d2 uses an Arc which is little heavy for what I need.

@sfackler
Copy link
Owner

sfackler commented Apr 9, 2019

What percentage of your runtime has your profiling indicated is spent in Arc code?

@enzious
Copy link
Author

enzious commented Apr 9, 2019

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.

@sfackler
Copy link
Owner

sfackler commented Apr 9, 2019

That wasn't really an answer to my question.

@enzious
Copy link
Author

enzious commented Apr 9, 2019

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.

@sfackler
Copy link
Owner

sfackler commented Apr 9, 2019

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.

@sfackler sfackler closed this Apr 9, 2019
@enzious
Copy link
Author

enzious commented Apr 9, 2019

What about a GenericClient trait?

@sfackler
Copy link
Owner

sfackler commented Apr 9, 2019

Sure, I'd be happy to add that trait back.

@enzious
Copy link
Author

enzious commented Apr 9, 2019

And you're right, I was thinking of Arc<Mutex<T>>

@colingm
Copy link
Contributor

colingm commented Dec 20, 2019

@sfackler did you ever look at bringing back the GenericConnection trait into the newer versions?

@sfackler
Copy link
Owner

Ah, I have not yet but it seems reasonable to do!

@colingm
Copy link
Contributor

colingm commented Dec 20, 2019

@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.

@sfackler
Copy link
Owner

The crate was rewritten from scratch, and the trait just never made it back in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants