wolf4ood/gremlin-rs

Strange function signatures

Closed this issue · 7 comments

It seems very un-Rusty to ask for Into instead of T. This is behavior that is not inherently known to the user, whereas if we were to just accept T, users could decide for themselves whether to do Into. An example would be:

    pub fn connect<T>(options: T) -> GremlinResult<GremlinClient>
    where
        T: Into<ConnectionOptions>,

replaced with

    pub fn connect(options: ConnectionOptions) -> GremlinResult<GremlinClient>

I'm willing to implement this as a breaking change.

Hi @jdemilledt

my i ask why this seems very un-Rusty?

Thanks

@jdemilledt

The main idea is that if you want to use the builder you can

either use

let client = GremlinClient::connect("localhost")?;

or the full ConnectionOptions builder

let client = GremlinClient::connect(
        ConnectionOptions::builder()
            .host("localhost")
            .port(8182)
            .pool_size(1)
            .build(),
    )?;

For more complex scenario

The idiom in Rust is that nothing happens implicitly. A user can choose to use into, or a second function can be added to take a string, but the current method is not idiomatic.

Hi @jdemilledt

the Into<T> pattern or similar in function parameters is widely used in projects, imho it provide a flexible and nicer APIs to users.

Would the usage of AsRef<T> in File API be not idiomatic?

https://rust-lang-nursery.github.io/api-guidelines/flexibility.html#functions-minimize-assumptions-about-parameters-by-using-generics-c-generic

That specific link is talking about different things that in the end are the same. Specifically, that example is about IntoIterator, with different types being able to be iterated over with the same item, whereas with this, it's an implicit conversion of a String, str, etc to a struct, which is not transparent.

Hi @jdemilledt

here a couple of libraries which uses the same pattern if Into

https://docs.rs/redis/0.11.0/redis/struct.Client.html#method.open

https://docs.rs/mysql/16.0.2/mysql/struct.Pool.html#method.new

I don't get it which is the big deal with implicit conversion of params.

Thanks

Thanks for showing me real world examples. Since those libs are popular and haven't had that changed, I guess people are fine with it. I stand corrected.