houqp commented on pull request #974:
URL: https://github.com/apache/arrow-datafusion/pull/974#issuecomment-913965570


   @xudong963 your analysis is correct :) However, the main benefit of that 
`impl Into<String>` generic argument is to give caller the flexibility to pass 
in the `path` variable either by reference or value.
   
   When the caller is passing `path` as `&str`, then there will be no 
difference between these two versions as you mentioned.
   
   When the caller pass in `path` as `String` type, then 
`ParquetTable::try_new(path: &str)` will end up with an extra copy because the 
signature forces it to write `ParquetTable::try_new(&path)`. While 
`ParquetTable::try_new(path: impl Into<String>)` will take ownership of `path` 
and avoid that copy entirely because `path.into` for String type will be 
optimized away by the compiler. This is useful when the caller knows it won't 
need to use the `path` variable anymore after calling `ParquetTable::try_new`, 
so it can safely pass it along by value.
   
   https://phaazon.net/blog/blog/on-owning-borrowing-pub-interface has a good 
summary on this topic if you are into more detailed analysis.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to