summaryrefslogtreecommitdiff
path: root/rust/src/string.rs
diff options
context:
space:
mode:
authorMason Reed <mason@vector35.com>2025-05-04 20:43:32 -0400
committerMason Reed <35282038+emesare@users.noreply.github.com>2025-05-12 17:45:24 -0400
commitf32f083c81a5034530ac33ad2bc460dd234186a5 (patch)
tree02e5799b595322b3a6967977ac69257eb023e882 /rust/src/string.rs
parente12dac56c123bcf39708cb381497753250eb1887 (diff)
[Rust] More cleanup regarding `BnString`
- Removed `to_string` shortcut from `BnString`. - Misc formatting
Diffstat (limited to 'rust/src/string.rs')
-rw-r--r--rust/src/string.rs16
1 files changed, 5 insertions, 11 deletions
diff --git a/rust/src/string.rs b/rust/src/string.rs
index 640731ff..5be623c1 100644
--- a/rust/src/string.rs
+++ b/rust/src/string.rs
@@ -15,6 +15,7 @@
//! String wrappers for core-owned strings and strings being passed to the core
use crate::rc::*;
+use crate::type_archive::TypeArchiveSnapshotId;
use crate::types::QualifiedName;
use std::borrow::Cow;
use std::ffi::{c_char, CStr, CString};
@@ -23,7 +24,6 @@ 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<String> {
@@ -72,7 +72,7 @@ impl BnString {
///
/// This expects the passed raw string to be owned, as in, freed by us.
pub unsafe fn into_string(raw: *mut c_char) -> String {
- Self::from_raw(raw).to_string()
+ Self::from_raw(raw).to_string_lossy().to_string()
}
/// Construct a BnString from an owned const char* allocated by BNAllocString
@@ -160,15 +160,9 @@ impl PartialEq for BnString {
impl Eq for BnString {}
-impl fmt::Display for BnString {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "{}", self.to_string_lossy())
- }
-}
-
impl fmt::Debug for BnString {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- self.to_string_lossy().fmt(f)
+ write!(f, "{}", self.to_string_lossy())
}
}
@@ -294,10 +288,10 @@ 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 {