Skip to content

Make std::io::TempDir::{new, new_in} accept a BytesContainer as a suffix #19447

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 1 commit into from

Conversation

csouth3
Copy link
Contributor

@csouth3 csouth3 commented Dec 2, 2014

This pull request addresses #19437. It was mentioned that Paths can be constructed with any BytesContainer, whereas TempDir's constructors specifically require an &str. There's no reason that TempDir's constructors shouldn't be able to accept any BytesContainer however, so long as the suffix is a valid UTF-8 string.

Closes #19437.

@@ -41,13 +41,24 @@ impl TempDir {

static CNT: atomic::AtomicUint = atomic::INIT_ATOMIC_UINT;

let suffix_str = match suffix.container_as_str() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the part that I'm unsure of. I like the idea of changing the parameter from &str to BytesContainer because that matches Path, but ultimately the suffix must still be a UTF-8 string, so the first solution that came to mind was to just return an error like this if that isn't the case, and proceed otherwise. But if we're just converting right to str anyway, does this commit make any sense? Thought I'd throw the PR out to start the discussion though.

@csouth3 csouth3 force-pushed the tmpdir-bytescontainer branch from a63e2c2 to 27ce252 Compare December 4, 2014 20:07
@csouth3
Copy link
Contributor Author

csouth3 commented Dec 4, 2014

@jmesmon Full disclosure, I'm still running make check on this revision. But this is already looking a lot cleaner to me, is this closer to what you were thinking?
EDIT: make check appears to be happy now.

@alexcrichton
Copy link
Member

@aturon and I recently finished taking a close look at all of std::io, but I think we missed TempDir by accident. Would you be ok holding off until we have a chance to review it? I personally prefer not using generics wherever possible, and it seems like somewhat overkill in this case as just because we can accept something doesn't necessarily mean we should take the monomorphization/documentation hit.

@csouth3
Copy link
Contributor Author

csouth3 commented Dec 6, 2014

@alexcrichton Totally. I just saw the open issue and thought I'd take a stab at fixing it, but obviously please just do what you find to be best!

@csouth3 csouth3 force-pushed the tmpdir-bytescontainer branch from 27ce252 to a556900 Compare December 7, 2014 07:26
@alexcrichton
Copy link
Member

Thanks for being patient @csouth3! After thinking about with with respect to rust-lang/rfcs#517 I don't think that this is actually the direction that we want to go in. We've realized that paths are not actually piles of bytes but rather piles of bytes on unix and piles of u16 on windows. This means that eventually this is not the right bound for this function.

Ideally this bound would be AsPath or AsOsStr, but the OsStr one is a bit odd and it's not necessarily a Path but rather a suffix to a path. In light of this I think we'll want to stick to &str for now (the common language of paths as unicode), and we can generalize later if necessary. Thanks for the PR regardless!

@csouth3
Copy link
Contributor Author

csouth3 commented Dec 18, 2014

Ah, totally didn't realize the inconsistency between paths on unix/windows. Definitely makes sense to leave it then, thanks for the info!

@csouth3 csouth3 deleted the tmpdir-bytescontainer branch December 18, 2014 21:30
lnicola pushed a commit to lnicola/rust that referenced this pull request Apr 28, 2025
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.

std::io::TempDir::{new,new_from} should use &[u8] as their suffix instead of &str
3 participants