pub mod raw;
pub mod include {
pub use crate::string::debug::raw::*;
}
pub struct DebugString {
pub inner: include::RawString,
}
impl DebugString {
pub fn new(value: std::ffi::CString) -> Self {
Self {
inner: include::RawString::new(value.as_ptr()),
}
}
pub fn push_cstring(&mut self, value: std::ffi::CString) -> Result<(), Box<dyn std::error::Error>> {
self.inner.push(value.as_ptr()).unwrap();
Ok(())
}
pub fn push_cstr(&mut self, value: &std::ffi::CStr) -> Result<(), Box<dyn std::error::Error>> {
self.inner.push(value.as_ptr()).unwrap();
Ok(())
}
pub fn get_cstring(&self) -> Option<std::ffi::CString> {
let res = self.inner.get().unwrap();
Some(unsafe { std::ffi::CString::from_raw(res as *mut ::std::os::raw::c_char) })
}
pub fn destroy(&mut self) -> Result<(), Box<dyn std::error::Error>> {
self.inner.destroy().unwrap();
Ok(())
}
pub fn get_cstr(&self) -> Option<&std::ffi::CStr> {
let res = self.inner.get().unwrap();
Some(unsafe { std::ffi::CStr::from_ptr(res) })
}
pub fn get_cstring_index(&self, index: usize) -> Option<std::ffi::CString> {
let res = self.inner.get_index(index).unwrap();
Some(unsafe { std::ffi::CString::from_raw(res as *mut ::std::os::raw::c_char) })
}
pub fn get_cstr_index(&self, index: usize) -> Option<&std::ffi::CStr> {
let res = self.inner.get_index(index).unwrap();
Some(unsafe { std::ffi::CStr::from_ptr(res) })
}
pub fn get_cstring_exact(&self, start: usize, end: usize) -> Option<std::ffi::CString> {
let res = self.inner.get_exact(start, end).unwrap();
Some(unsafe { std::ffi::CString::from_raw(res as *mut ::std::os::raw::c_char) })
}
pub fn get_cstr_exact(&self, start: usize, end: usize) -> Option<&std::ffi::CStr> {
let res = self.inner.get_exact(start, end).unwrap();
Some(unsafe { std::ffi::CStr::from_ptr(res) })
}
pub fn remove_cstring(&mut self, value: std::ffi::CString) -> Result<(), Box<dyn std::error::Error>> {
self.inner.remove(value.as_ptr()).unwrap();
Ok(())
}
pub fn remove_cstr(&mut self, value: &std::ffi::CStr) -> Result<(), Box<dyn std::error::Error>> {
self.inner.remove(value.as_ptr()).unwrap();
Ok(())
}
pub fn len(&self) -> Option<usize> {
let res = self.inner.len().unwrap();
Some(res)
}
pub fn size(&self) -> Option<usize> {
let res = self.inner.size().unwrap();
Some(res)
}
pub fn size_from(&self, index: usize) -> Option<usize> {
let res = self.inner.size_from(index).unwrap();
Some(res)
}
pub fn status(&self) -> Option<usize> {
let res = self.inner.status().unwrap();
Some(res)
}
pub fn replace(&mut self, start: usize, end: usize) -> Result<(), Box<dyn std::error::Error>> {
self.inner.replace(start, end).unwrap();
Ok(())
}
pub fn instance(&self) -> Option<DebugString> {
let new = Self::default();
Some(new)
}
}
impl Default for DebugString {
fn default() -> Self {
Self {
inner: include::RawString::new(std::ptr::null()),
}
}
}
impl Clone for DebugString {
fn clone(&self) -> Self {
Self {
inner: self.inner.clone(),
}
}
fn clone_from(&mut self, source: &Self) {
self.inner = source.inner.clone();
}
}
impl From<std::ffi::CString> for DebugString {
fn from(value: std::ffi::CString) -> Self {
Self {
inner: include::RawString::new(value.as_ptr()),
}
}
}
impl From<&std::ffi::CStr> for DebugString {
fn from(value: &std::ffi::CStr) -> Self {
Self {
inner: include::RawString::new(value.as_ptr()),
}
}
}
impl From<include::RawString> for DebugString {
fn from(value: include::RawString) -> Self {
Self {
inner: value,
}
}
}
impl Copy for DebugString {}
unsafe impl Send for DebugString {}
unsafe impl Sync for DebugString {}