From 788a8b7091bbdde77817030e0836d7a7a786fd99 Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Sun, 4 May 2025 19:47:55 -0400 Subject: [Rust] Simplify usage surrounding c strings `cstring.as_ref().as_ptr() as *const c_char` -> `cstring.as_ptr()` `cstring.as_ref().as_ptr() as *mut _` -> `cstring.as_ptr()` `cstring.as_ptr() as *const c_char` -> `cstring.as_ptr()` With a few fixes for cstrings that might be dropped prematurely. --- rust/src/string.rs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'rust/src/string.rs') diff --git a/rust/src/string.rs b/rust/src/string.rs index 17fcf911..640731ff 100644 --- a/rust/src/string.rs +++ b/rust/src/string.rs @@ -23,6 +23,7 @@ use std::hash::{Hash, Hasher}; use std::mem; use std::ops::Deref; use std::path::{Path, PathBuf}; +use crate::type_archive::TypeArchiveSnapshotId; // TODO: Remove or refactor this. pub(crate) fn raw_to_string(ptr: *const c_char) -> Option { @@ -291,6 +292,14 @@ unsafe impl AsCStr for &Path { } } +unsafe impl AsCStr for TypeArchiveSnapshotId { + type Result = CString; + + fn to_cstr(self) -> Self::Result { + self.to_string().to_cstr() + } +} + pub trait IntoJson { type Output: AsCStr; -- cgit v1.3.1