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

added Error and Display impl for std::ffi::FromBytesWithNulError #39960

Merged
merged 2 commits into from
Mar 1, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/libstd/ffi/c_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,20 @@ impl From<NulError> for io::Error {
}
}

#[unstable(feature = "frombyteswithnulerror_impls", reason = "recently added", issue = "39925")]
Copy link
Member

Choose a reason for hiding this comment

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

Oh unfortunately impls aren't subject to stability the same way as other parts of the standard library, so these'll be "insta-stable" so it's ok to just go ahead and tag this with #[stable]

impl Error for FromBytesWithNulError {
fn description(&self) -> &str {
"data provided is not null terminated or contains an interior nul byte"
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't it be interior null byte?

Copy link
Contributor

@codyps codyps Feb 24, 2017

Choose a reason for hiding this comment

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

Not necessarily. https://en.wikipedia.org/wiki/Null_character

Also note the name of the error type.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah I see, thanks for the correction @jmesmon

}
}

#[unstable(feature = "frombyteswithnulerror_impls", reason = "recently added", issue = "39925")]
impl fmt::Display for FromBytesWithNulError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.description().fmt(f)
}
}

impl IntoStringError {
/// Consumes this error, returning original `CString` which generated the
/// error.
Expand Down