diff options
| author | Kevin Butler <haqkrs@gmail.com> | 2014-04-08 02:30:08 +0100 |
|---|---|---|
| committer | Kevin Butler <haqkrs@gmail.com> | 2014-04-11 20:27:01 +0100 |
| commit | d1e20488a5d1258b1582caa2db77e5210b8bd28f (patch) | |
| tree | 1f2bd0e6c2fefa86deba85d0d6f7c7d2d38b29df /src/libstd/path/mod.rs | |
| parent | 65abf96fb6630d7ddbcdc3b39f599c02ecfc2f1e (diff) | |
| download | rust-d1e20488a5d1258b1582caa2db77e5210b8bd28f.tar.gz rust-d1e20488a5d1258b1582caa2db77e5210b8bd28f.zip | |
Parameterize contains_nul for BytesContainer.
Diffstat (limited to 'src/libstd/path/mod.rs')
| -rw-r--r-- | src/libstd/path/mod.rs | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/libstd/path/mod.rs b/src/libstd/path/mod.rs index a0097469e56..54a8d813137 100644 --- a/src/libstd/path/mod.rs +++ b/src/libstd/path/mod.rs @@ -158,7 +158,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// See individual Path impls for additional restrictions. #[inline] fn new<T: BytesContainer>(path: T) -> Self { - assert!(!contains_nul(path.container_as_bytes())); + assert!(!contains_nul(&path)); unsafe { GenericPathUnsafe::new_unchecked(path) } } @@ -166,7 +166,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// The resulting Path will always be normalized. #[inline] fn new_opt<T: BytesContainer>(path: T) -> Option<Self> { - if contains_nul(path.container_as_bytes()) { + if contains_nul(&path) { None } else { Some(unsafe { GenericPathUnsafe::new_unchecked(path) }) @@ -274,7 +274,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// Fails the task if the filename contains a NUL. #[inline] fn set_filename<T: BytesContainer>(&mut self, filename: T) { - assert!(!contains_nul(filename.container_as_bytes())); + assert!(!contains_nul(&filename)); unsafe { self.set_filename_unchecked(filename) } } /// Replaces the extension with the given byte vector or string. @@ -286,7 +286,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// /// Fails the task if the extension contains a NUL. fn set_extension<T: BytesContainer>(&mut self, extension: T) { - assert!(!contains_nul(extension.container_as_bytes())); + assert!(!contains_nul(&extension)); // borrowck causes problems here too let val = { match self.filename() { @@ -376,7 +376,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// Fails the task if the path contains a NUL. #[inline] fn push<T: BytesContainer>(&mut self, path: T) { - assert!(!contains_nul(path.container_as_bytes())); + assert!(!contains_nul(&path)); unsafe { self.push_unchecked(path) } } /// Pushes multiple paths (as byte vectors or strings) onto `self`. @@ -589,8 +589,8 @@ impl<'a> BytesContainer for str::MaybeOwned<'a> { } #[inline(always)] -fn contains_nul(v: &[u8]) -> bool { - v.iter().any(|&x| x == 0) +fn contains_nul<T: BytesContainer>(v: &T) -> bool { + v.container_as_bytes().iter().any(|&x| x == 0) } #[cfg(test)] |
