Add a From<&[u8]> interface for offset for future artichoke-backend use
@@ -185,6 +185,13 @@ impl From<&str> for Offset {
}
}
+impl From<&[u8]> for Offset {
+ fn from(input: &[u8]) -> Self {
+ let input = str::from_utf8(input).expect("Invalid UTF8");
+ Offset::from(input)
+ }
+}
+
impl From<String> for Offset {
fn from(input: String) -> Self {
Offset::from(input.as_str())
@@ -238,6 +245,13 @@ mod tests {
assert!(matches!(offset, Offset::Utc));
}
+ #[test]
+ fn from_binary_string() {
+ let tz: &[u8] = b"Z";
+ let offset = Offset::from(tz);
+ assert!(matches!(offset, Offset::Utc));
+ }
+
#[test]
fn from_str_hh_mm() {
assert_eq!(0, offset_seconds_from_fixed_offset("+0000"));
