mlir: Add helper to go from MlirStringRef to &str
@@ -11,3 +11,11 @@ pub unsafe fn mlirStringRefCreateFromStr(s: impl AsRef<str>) -> MlirStringRef {
length: s.len() as size_t,
}
}
+
+pub unsafe fn mlirStringRefToStr<R>(s: MlirStringRef, f: impl Fn(&str) -> R) -> R {
+ f(std::str::from_utf8(std::slice::from_raw_parts(
+ s.data as *const _,
+ s.length as usize,
+ ))
+ .expect("utf8 string"))
+}
