}
}
- /// Create a C-compatible string from a byte vector without checking for
+ /// Creates a C-compatible string from a byte vector without checking for
/// interior 0 bytes.
///
- /// This method is equivalent to `from_vec` except that no runtime assertion
- /// is made that `v` contains no 0 bytes.
+ /// This method is equivalent to `new` except that no runtime assertion
+ /// is made that `v` contains no 0 bytes, and it requires an actual
+ /// byte vector, not anyhting that can be converted to one with Into.
#[stable(feature = "rust1", since = "1.0.0")]
pub unsafe fn from_vec_unchecked(mut v: Vec<u8>) -> CString {
v.push(0);
}
}
-#[stable(feature = "rust1", since = "1.0.0")]
-#[allow(deprecated)]
-impl From<NulError> for old_io::IoError {
- fn from(_: NulError) -> old_io::IoError {
- old_io::IoError {
- kind: old_io::IoErrorKind::InvalidInput,
- desc: "data provided contains a nul byte",
- detail: None
- }
- }
-}
-
impl CStr {
- /// Cast a raw C string to a safe C string wrapper.
+ /// Casts a raw C string to a safe C string wrapper.
///
/// This function will cast the provided `ptr` to the `CStr` wrapper which
/// allows inspection and interoperation of non-owned C strings. This method
self.octets()[0] >= 224 && self.octets()[0] <= 239
}
- /// Convert this address to an IPv4-compatible IPv6 address
+ /// Returns true if this is a broadcast address.
+ ///
+ /// A broadcast address has all octets set to 255 as defined in RFC 919
+ pub fn is_broadcast(&self) -> bool {
+ self.octets()[0] == 255 && self.octets()[1] == 255 &&
+ self.octets()[2] == 255 && self.octets()[3] == 255
+ }
+
+ /// Returns true if this address is in a range designated for documentation
+ ///
+ /// This is defined in RFC 5737
+ /// - 192.0.2.0/24 (TEST-NET-1)
+ /// - 198.51.100.0/24 (TEST-NET-2)
+ /// - 203.0.113.0/24 (TEST-NET-3)
+ pub fn is_documentation(&self) -> bool {
+ match(self.octets()[0], self.octets()[1], self.octets()[2], self.octets()[3]) {
+ (192, _, 2, _) => true,
+ (198, 51, 100, _) => true,
+ (203, _, 113, _) => true,
+ _ => false
+ }
+ }
+
+ /// Converts this address to an IPv4-compatible IPv6 address
///
/// a.b.c.d becomes ::a.b.c.d
#[stable(feature = "rust1", since = "1.0.0")]