-
-
Notifications
You must be signed in to change notification settings - Fork 793
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
Implement Serialize/Deserialize for OsStr/OsString #824
Conversation
18fbaa8
to
d968d0f
Compare
I have to run but the test is wrong - the windows test says "Widnows" but is skipped because of the early return in the previous test. I would prefer to update the test macro to look like: #[cfg(unix)]
test_osstring {
{
use std::os::unix::ffi::OsStringExt;
OsString::from_vec(vec![1, 2, 3])
} => &[
/* ... */
],
}
#[cfg(windows)]
test_osstring {
{
use std::os::windows::ffi::OsStringExt;
OsString::from_wide(&[1, 2, 3])
} => &[
/* ... */
],
} If you don't get to it I will do this myself this afternoon and then publish a release for you. |
This commit implements the two serde traits for the libstd `OsStr` and `OsString` types. This came up as a use case during implementing sccache where we're basically just doing IPC to communicate paths around. Additionally the `Path` and `PathBuf` implementations have been updated to delegate to the os string ones. These types are platform-specific, however, so the serialization/deserialization isn't trivial. Currently this "fakes" a newtype variant for Unix/Windows to prevent cross-platform serialization/deserialization. This means if you're doing IPC within the same OS (e.g. Windows to Windows) then serialization should be infallible. If you're doing IPC across platforms (e.g. Unix to Windows) then using `OsString` is guaranteed to fail as bytes from one OS won't deserialize on the other (even if they're unicode).
d968d0f
to
ce68743
Compare
Oops good catch, I couldn't quite get |
Thanks, I released this in serde 0.9.12 and filed mozilla/sccache#93 to follow up on the sccache side. |
Thanks @dtolnay! |
@alexcrichton A bit late on this, but one comment: shouldn't the newtype have a separate variant for redox? Because stdlib has a separate implementation for redox and I assume that there's a reason for that. |
I think that's a backwards compatible extension? |
This commit implements the two serde traits for the libstd
OsStr
andOsString
types. This came up as a use case during implementing sccache wherewe're basically just doing IPC to communicate paths around. Additionally the
Path
andPathBuf
implementations have been updated to delegate to the osstring ones.
These types are platform-specific, however, so the serialization/deserialization
isn't trivial. Currently this "fakes" a newtype variant for Unix/Windows to
prevent cross-platform serialization/deserialization. This means if you're doing
IPC within the same OS (e.g. Windows to Windows) then serialization should be
infallible. If you're doing IPC across platforms (e.g. Unix to Windows) then
using
OsString
is guaranteed to fail as bytes from one OS won't deserialize onthe other (even if they're unicode).
Closes #823