alamb commented on code in PR #7718:
URL: https://github.com/apache/arrow-rs/pull/7718#discussion_r2159071316


##########
parquet-variant/src/variant.rs:
##########
@@ -29,6 +29,37 @@ mod list;
 mod metadata;
 mod object;
 
+const MAX_SHORT_STRING_SIZE: usize = 0x3F;
+
+/// A Variant [`ShortString`]
+///
+/// This implementation is a zero cost wrapper over `&str` that ensures
+/// the length of the underlying string is a valid Variant short string (63 
bytes or less)
+#[derive(Debug, Clone, Copy, PartialEq)]
+pub struct ShortString<'a>(pub(crate) &'a str);
+
+impl<'a> ShortString<'a> {
+    /// Attempts to interpret `value` as a variant short string value.  
+    ///
+    /// # Validation
+    ///
+    /// This constructor verifies that `value` is shorter than or equal to 
`MAX_SHORT_STRING_SIZE`
+    pub fn try_new(value: &'a str) -> Result<Self, ArrowError> {
+        if value.len() > MAX_SHORT_STRING_SIZE {
+            return Err(ArrowError::InvalidArgumentError(format!(
+                "value is larger than {MAX_SHORT_STRING_SIZE} bytes"
+            )));
+        }
+
+        Ok(Self(value))
+    }
+
+    /// Returns the underlying Variant short string as a &str
+    pub fn as_str(&self) -> &'a str {
+        self.0
+    }
+}
+

Review Comment:
   Nice!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to