Skip to content
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

add Traits? #2

Open
vitiral opened this issue Jan 29, 2018 · 4 comments
Open

add Traits? #2

vitiral opened this issue Jan 29, 2018 · 4 comments

Comments

@vitiral
Copy link

vitiral commented Jan 29, 2018

Hey, I love the library!

I was thinking adding a trait which is implemented for str would be useful. The end result would be:

  • "~/foo/bar".expand(): Calls shellexpand::full on the str.
  • "~/foo/bar".expand_tilde(): calls shellexpand::tilde on the str.

I fell like these are the two most commonly needed methods and would improve the eronomics of this library.

I feel the docs could also be improved to suggest these two functions + trait at the very beginning. Right now shellexpand::full isn't mentioned until the 4th paragraph when most users of this library will be looking for either full or tilde and a brief overview of what they do.

@netvl
Copy link
Owner

netvl commented Feb 9, 2018

I don't think that adding traits is a good idea, since it is not really an idiomatic approach. Libraries like this one usually provide top-level functions, which are actually easier to use than traits:

use shellexpand::StringExpandExt;

"a".expand_full();

vs

use shellexpand;

shellexpand::full("a");

IDEs will also suggest all of the function names in the second case; they also can usually suggest added trait methods in the first case, but it is less reliable and requires the user to import the trait explicitly. The latter can probably be mitigated by having some special module for glob imports, e.g. use shellexpand::prelude::* or use shellexpand::traits::*, but it so much of complexity for such a simple library I don't think it is worth potential syntactic improvements

As for the thing about documentation, yes, I can see what you mean. I wrote documentation using the "bottom-up" approach, with high-level functions described as emergent from more general functions, but I think that indeed mentioning the most common ones in the beginning would be a good thing. I'll fix the docs as soon as I'm able to. Thanks!

@vitiral
Copy link
Author

vitiral commented Feb 9, 2018

Sorry I forgot to take back the stuff about the traits - on further thought I think you are absolutely right!

The doc changes would be great. Thanks again for the awesome lib!

@ijackson
Copy link

ijackson commented Aug 3, 2022

Hi. As discussed in #17 I am taking over maintenance of this crate. The new repository is here: https://gitlab.com/ijackson/rust-shellexpand

I think that an extension trait, as proposed, would be a nice addition. I haven't filed an issue in my new repo about this, but I would welcome an MR.

@vitiral
Copy link
Author

vitiral commented Aug 3, 2022

I personally took back my thoughts on a trait, but feel free to implement/accept if you still think it's valuable :D

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

No branches or pull requests

3 participants