pub struct basic_string<CharT: AbiType + 'static> { /* private fields */ }Expand description
cpp class: template<class CharT, class Traits, class Allocator> std::basic_string<CharT, Traits, Allocator>
Implementations§
Source§impl<CharT: AbiType + 'static> basic_string<CharT>
impl<CharT: AbiType + 'static> basic_string<CharT>
pub const npos: usize = usize::MAX
Sourcepub fn substr(&self, pos: usize, len: usize) -> Self
pub fn substr(&self, pos: usize, len: usize) -> Self
如果pos超出范围,会返回空字符串.
use hicc_std::string;
let mut s = string::from(hicc::cstr!("abc"));
let substr = s.substr(1, 2);
assert_eq!(substr.as_cstr(), hicc::cstr!("bc"));Sourcepub fn append_str(&mut self, s: &Self, subpos: usize, sublen: usize)
pub fn append_str(&mut self, s: &Self, subpos: usize, sublen: usize)
如果subpos超出范围则不做任何改变.
use hicc_std::string;
let mut s1 = string::from(hicc::cstr!("abc"));
let s2 = string::from(hicc::cstr!("def"));
s1.append_str(&s2, 0, 2);
assert_eq!(s1.as_cstr(), hicc::cstr!("abcde"));Sourcepub fn insert_str(&mut self, pos: usize, s: &Self, subpos: usize, sublen: usize)
pub fn insert_str(&mut self, pos: usize, s: &Self, subpos: usize, sublen: usize)
如果subpos超出范围不做任何改变, 如果pos超出范围则追加到最后.
use hicc_std::string;
let mut s1 = string::from(hicc::cstr!("abc"));
let mut s2 = string::from(hicc::cstr!("def"));
s1.insert_str(0, &s2, 0, string::npos);
assert_eq!(s1.as_cstr(), hicc::cstr!("defabc"));
s1.insert_str(100, &s2, 0, string::npos);
assert_eq!(s1.as_cstr(), hicc::cstr!("defabcdef"));Sourcepub fn insert(&mut self, pos: usize, n: usize, c: CharT::InputType)
pub fn insert(&mut self, pos: usize, n: usize, c: CharT::InputType)
如果pos超出范围则追加到最后.
use hicc_std::string;
let mut s = string::from(hicc::cstr!("abc"));
s.insert(0, 3, b'd' as i8);
assert_eq!(s.as_cstr(), hicc::cstr!("dddabc"));
s.insert(110, 3, b'd' as i8);
assert_eq!(s.as_cstr(), hicc::cstr!("dddabcddd"));Sourcepub fn replace_str(
&mut self,
pos: usize,
len: usize,
s: &Self,
subpos: usize,
sublen: usize,
)
pub fn replace_str( &mut self, pos: usize, len: usize, s: &Self, subpos: usize, sublen: usize, )
如果pos或者subpos超出范围则不做任何改变.
use hicc_std::string;
let mut s1 = string::from(hicc::cstr!("abc"));
let mut s2 = string::from(hicc::cstr!("de"));
s1.replace_str(0, string::npos, &s2, 0, string::npos);
assert_eq!(s1.as_cstr(), hicc::cstr!("de"));Sourcepub fn replace(&mut self, pos: usize, len: usize, n: usize, c: CharT::InputType)
pub fn replace(&mut self, pos: usize, len: usize, n: usize, c: CharT::InputType)
如果pos超出范围则不做任何改变.
use hicc_std::string;
let mut s = string::from(hicc::cstr!("abc"));
s.replace(0, string::npos, 1, b'd' as i8);
assert_eq!(s.as_cstr(), hicc::cstr!("d"));Sourcepub fn assign_str(&mut self, s: &Self, subpos: usize, sublen: usize)
pub fn assign_str(&mut self, s: &Self, subpos: usize, sublen: usize)
如果subpos超出范围则不做任何改变.
use hicc_std::string;
let mut s1 = string::from(hicc::cstr!("abc"));
let mut s2 = string::from(hicc::cstr!("de"));
s1.assign_str(&s2, 0, string::npos);
assert_eq!(s1.as_cstr(), hicc::cstr!("de"));Sourcepub fn erase(&mut self, pos: usize, len: usize)
pub fn erase(&mut self, pos: usize, len: usize)
如果pos超出范围则不做任何改变.
use hicc_std::string;
let mut s = string::from(hicc::cstr!("abc"));
s.erase(1, 1);
assert_eq!(s.as_cstr(), hicc::cstr!("ac"));Sourcepub fn pop_back(&mut self)
pub fn pop_back(&mut self)
如果为空则不做任何改变.
use hicc_std::string;
let mut s = string::from(hicc::cstr!("abc"));
s.pop_back();
assert_eq!(s.as_cstr(), hicc::cstr!("ab"));Sourcepub fn get(&self, pos: usize) -> Option<CharT::OutputRef<'_>>
pub fn get(&self, pos: usize) -> Option<CharT::OutputRef<'_>>
use hicc_std::string;
let s = string::from(hicc::cstr!("abc"));
assert_eq!(s.get(0), Some(&(b'a' as i8)));
assert_eq!(s.get(3), None);Sourcepub fn get_mut(&mut self, pos: usize) -> Option<CharT::OutputRefMut<'_>>
pub fn get_mut(&mut self, pos: usize) -> Option<CharT::OutputRefMut<'_>>
use hicc_std::string;
let mut s = string::from(hicc::cstr!("abc"));
assert!(s.get_mut(0).is_some());
assert_eq!(*s.get_mut(0).unwrap(), b'a' as i8);
assert_eq!(s.get(3), None);Sourcepub fn c_str(
&self,
) -> <CharT as AbiType>::OutputPtr<'static, *const <CharT as AbiType>::InputType, 1usize>
pub fn c_str( &self, ) -> <CharT as AbiType>::OutputPtr<'static, *const <CharT as AbiType>::InputType, 1usize>
use std::ffi::CStr;
use hicc_std::string;
let s = string::from(hicc::cstr!("abc"));
let cstr = unsafe { CStr::from_ptr(s.c_str()) };
assert_eq!(cstr, hicc::cstr!("abc"));Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
use hicc_std::string;
let s = string::new();
assert!(s.is_empty());Sourcepub fn size(&self) -> usize
pub fn size(&self) -> usize
use hicc_std::string;
let s = string::new();
assert_eq!(s.size(), 0);Sourcepub fn max_size(&self) -> usize
pub fn max_size(&self) -> usize
use hicc_std::string;
let s = string::new();
println!("s.max_size = {}", s.max_size());Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
use hicc_std::string;
let s = string::new();
println!("s.capacity = {}", s.capacity());Sourcepub fn resize(&mut self, n: usize, c: <CharT as AbiType>::InputType)
pub fn resize(&mut self, n: usize, c: <CharT as AbiType>::InputType)
use hicc_std::string;
let mut s = string::from(hicc::cstr!("a"));
s.resize(3, b'c' as i8);
assert_eq!(s.as_cstr(), hicc::cstr!("acc"));Sourcepub fn reserve(&mut self, n: usize)
pub fn reserve(&mut self, n: usize)
use hicc_std::string;
let mut s = string::from(hicc::cstr!("abc"));
s.reserve(100);
println!("s.capacity = {}", s.capacity());Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
use hicc_std::string;
let mut s = string::from(hicc::cstr!("abc"));
s.clear();
assert!(s.is_empty());Sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
use hicc_std::string;
let mut s = string::from(hicc::cstr!("abc"));
s.reserve(100);
println!("before shrink_to_fit: capacity = {}", s.capacity());
s.assign(10, b'c' as i8);
s.shrink_to_fit();
println!("after shrink_to_fit: capacity = {}", s.capacity());Sourcepub fn compare(
&self,
other: &<basic_string<CharT> as AbiType>::InputType,
) -> i32
pub fn compare( &self, other: &<basic_string<CharT> as AbiType>::InputType, ) -> i32
use hicc_std::string;
let s1 = string::from(hicc::cstr!("abc"));
let s2 = string::from(hicc::cstr!("abd"));
assert!(s1 < s2);
assert!(s1 != s2);Sourcepub fn find_str(
&self,
target: &<basic_string<CharT> as AbiType>::InputType,
pos: usize,
) -> usize
pub fn find_str( &self, target: &<basic_string<CharT> as AbiType>::InputType, pos: usize, ) -> usize
use hicc_std::string;
let s1 = string::from(hicc::cstr!("abcdef"));
let s2 = string::from(hicc::cstr!("bcd"));
assert_eq!(s1.find_str(&s2, 0), 1);Sourcepub fn find(&self, c: <CharT as AbiType>::InputType, pos: usize) -> usize
pub fn find(&self, c: <CharT as AbiType>::InputType, pos: usize) -> usize
use hicc_std::string;
let s = string::from(hicc::cstr!("abcdef"));
assert_eq!(s.find(b'c' as i8, 1), 2);Sourcepub fn rfind_str(
&self,
target: &<basic_string<CharT> as AbiType>::InputType,
pos: usize,
) -> usize
pub fn rfind_str( &self, target: &<basic_string<CharT> as AbiType>::InputType, pos: usize, ) -> usize
use hicc_std::string;
let s1 = string::from(hicc::cstr!("abcdef"));
let s2 = string::from(hicc::cstr!("bcd"));
assert_eq!(s1.rfind_str(&s2, string::npos), 1);Sourcepub fn rfind(&self, c: <CharT as AbiType>::InputType, pos: usize) -> usize
pub fn rfind(&self, c: <CharT as AbiType>::InputType, pos: usize) -> usize
use hicc_std::string;
let s = string::from(hicc::cstr!("abcdef"));
assert_eq!(s.rfind(b'c' as i8, string::npos), 2);Sourcepub fn find_first_of(
&self,
target: &<basic_string<CharT> as AbiType>::InputType,
pos: usize,
) -> usize
pub fn find_first_of( &self, target: &<basic_string<CharT> as AbiType>::InputType, pos: usize, ) -> usize
use hicc_std::string;
let s1 = string::from(hicc::cstr!("abcdef"));
let s2 = string::from(hicc::cstr!("dfb"));
assert_eq!(s1.find_first_of(&s2, 0), 1);Sourcepub fn find_first(&self, c: <CharT as AbiType>::InputType, pos: usize) -> usize
pub fn find_first(&self, c: <CharT as AbiType>::InputType, pos: usize) -> usize
use hicc_std::string;
let s = string::from(hicc::cstr!("abcabc"));
assert_eq!(s.find_first(b'c' as i8, 0), 2);Sourcepub fn find_last_of(
&self,
target: &<basic_string<CharT> as AbiType>::InputType,
pos: usize,
) -> usize
pub fn find_last_of( &self, target: &<basic_string<CharT> as AbiType>::InputType, pos: usize, ) -> usize
use hicc_std::string;
let s1 = string::from(hicc::cstr!("abcdef"));
let s2 = string::from(hicc::cstr!("dfb"));
assert_eq!(s1.find_last_of(&s2, string::npos), 5);Sourcepub fn find_last(&self, c: <CharT as AbiType>::InputType, pos: usize) -> usize
pub fn find_last(&self, c: <CharT as AbiType>::InputType, pos: usize) -> usize
use hicc_std::string;
let s = string::from(hicc::cstr!("abcabc"));
assert_eq!(s.find_last(b'c' as i8, string::npos), 5);Sourcepub fn find_first_not_of(
&self,
target: &<basic_string<CharT> as AbiType>::InputType,
pos: usize,
) -> usize
pub fn find_first_not_of( &self, target: &<basic_string<CharT> as AbiType>::InputType, pos: usize, ) -> usize
use hicc_std::string;
let s1 = string::from(hicc::cstr!("abcdef"));
let s2 = string::from(hicc::cstr!("abc"));
assert_eq!(s1.find_first_not_of(&s2, 0), 3);Sourcepub fn find_first_not(
&self,
c: <CharT as AbiType>::InputType,
pos: usize,
) -> usize
pub fn find_first_not( &self, c: <CharT as AbiType>::InputType, pos: usize, ) -> usize
use hicc_std::string;
let s = string::from(hicc::cstr!("abcabc"));
assert_eq!(s.find_first_not(b'a' as i8, 0), 1);Sourcepub fn find_last_not_of(
&self,
target: &<basic_string<CharT> as AbiType>::InputType,
pos: usize,
) -> usize
pub fn find_last_not_of( &self, target: &<basic_string<CharT> as AbiType>::InputType, pos: usize, ) -> usize
use hicc_std::string;
let s1 = string::from(hicc::cstr!("abcdef"));
let s2 = string::from(hicc::cstr!("def"));
assert_eq!(s1.find_last_not_of(&s2, string::npos), 2);Sourcepub fn find_last_not(
&self,
c: <CharT as AbiType>::InputType,
pos: usize,
) -> usize
pub fn find_last_not( &self, c: <CharT as AbiType>::InputType, pos: usize, ) -> usize
use hicc_std::string;
let s = string::from(hicc::cstr!("abcabc"));
assert_eq!(s.find_last_not(b'c' as i8, string::npos), 4);Sourcepub fn append(&mut self, n: usize, c: <CharT as AbiType>::InputType)
pub fn append(&mut self, n: usize, c: <CharT as AbiType>::InputType)
use hicc_std::string;
let mut s = string::from(hicc::cstr!("abc"));
s.append(1, b'd' as i8);
assert_eq!(s.as_cstr(), hicc::cstr!("abcd"));Sourcepub fn assign(&mut self, n: usize, c: <CharT as AbiType>::InputType)
pub fn assign(&mut self, n: usize, c: <CharT as AbiType>::InputType)
use hicc_std::string;
let mut s = string::from(hicc::cstr!("abc"));
s.assign(1, b'd' as i8);
assert_eq!(s.as_cstr(), hicc::cstr!("d"));Sourcepub fn push_back(&mut self, c: <CharT as AbiType>::InputType)
pub fn push_back(&mut self, c: <CharT as AbiType>::InputType)
use hicc_std::string;
let mut s = string::from(hicc::cstr!("abc"));
s.push_back(b'd' as i8);
assert_eq!(s.as_cstr(), hicc::cstr!("abcd"));Sourcepub fn swap(&mut self, other: &mut <basic_string<CharT> as AbiType>::InputType)
pub fn swap(&mut self, other: &mut <basic_string<CharT> as AbiType>::InputType)
use hicc_std::string;
let mut s1 = string::from(hicc::cstr!("abc"));
let mut s2 = string::from(hicc::cstr!("de"));
s1.swap(&mut s2);
assert_eq!(s1.as_cstr(), hicc::cstr!("de"));
assert_eq!(s2.as_cstr(), hicc::cstr!("abc"));Source§impl<T: Sized + 'static> basic_string<Pod<T>>
impl<T: Sized + 'static> basic_string<Pod<T>>
Sourcepub fn as_slice(&self) -> &[T]
pub fn as_slice(&self) -> &[T]
use hicc_std::string;
let mut s = string::with_cstr(hicc::cstr!("bcd"));
assert_eq!(s.as_slice(), &[b'b' as i8, b'c' as i8, b'd' as i8]);Sourcepub fn as_slice_mut(&mut self) -> &mut [T]
pub fn as_slice_mut(&mut self) -> &mut [T]
use hicc_std::string;
let mut s = string::with_cstr(hicc::cstr!("abc"));
s.as_slice_mut().iter_mut().for_each(|mut c| { *c += 1; });
assert_eq!(s.as_slice(), &[b'b' as i8, b'c' as i8, b'd' as i8]);Source§impl basic_string<Pod<i8>>
impl basic_string<Pod<i8>>
Source§impl basic_string<Pod<i16>>
impl basic_string<Pod<i16>>
Source§impl basic_string<Pod<i32>>
impl basic_string<Pod<i32>>
Source§impl basic_string<Pod<i8>>
impl basic_string<Pod<i8>>
Sourcepub fn new() -> <string as AbiType>::OutputType
pub fn new() -> <string as AbiType>::OutputType
cpp global function: std::unique_ptr<std::string> hicc::make_unique<std::string>()
Source§impl basic_string<Pod<i8>>
impl basic_string<Pod<i8>>
Source§impl basic_string<Pod<i8>>
impl basic_string<Pod<i8>>
Source§impl basic_string<Pod<i16>>
impl basic_string<Pod<i16>>
Sourcepub fn new() -> <u16string as AbiType>::OutputType
pub fn new() -> <u16string as AbiType>::OutputType
cpp global function: std::unique_ptr<std::u16string> hicc::make_unique<std::u16string>()
Source§impl basic_string<Pod<i16>>
impl basic_string<Pod<i16>>
Source§impl basic_string<Pod<i32>>
impl basic_string<Pod<i32>>
Sourcepub fn new() -> <u32string as AbiType>::OutputType
pub fn new() -> <u32string as AbiType>::OutputType
cpp global function: std::unique_ptr<std::u32string> hicc::make_unique<std::u32string>()
Trait Implementations§
Source§impl<CharT: AbiType + 'static> AbiClass for basic_string<CharT>
impl<CharT: AbiType + 'static> AbiClass for basic_string<CharT>
Source§fn get_raw_obj(&self) -> *const ()
fn get_raw_obj(&self) -> *const ()
仅内部使用.返回原始指针,等同于
c++侧的指针。Source§unsafe fn into_unique(self) -> Self
unsafe fn into_unique(self) -> Self
Safety Read more
fn as_mut(&mut self) -> ClassRefMut<'_, Self>
fn as_ptr(&self) -> ClassPtr<'_, Self>
fn as_mut_ptr(&mut self) -> ClassMutPtr<'_, Self>
Source§fn into_ref(self) -> ClassRef<'static, Self>
fn into_ref(self) -> ClassRef<'static, Self>
T, ClassRef<'_, T>, ClassRefMut<'_, T>, ClassPtr<'_, T>, ClassMutPtr<'_, T>作为返回值实质是等价.Source§fn into_mut(self) -> ClassRefMut<'static, Self>
fn into_mut(self) -> ClassRefMut<'static, Self>
T, ClassRef<'_, T>, ClassRefMut<'_, T>, ClassPtr<'_, T>, ClassMutPtr<'_, T>作为返回值实质是等价.Source§fn into_ptr(self) -> ClassPtr<'static, Self>
fn into_ptr(self) -> ClassPtr<'static, Self>
T, ClassRef<'_, T>, ClassRefMut<'_, T>, ClassPtr<'_, T>, ClassMutPtr<'_, T>作为返回值实质是等价.Source§fn into_mut_ptr(self) -> ClassMutPtr<'static, Self>
fn into_mut_ptr(self) -> ClassMutPtr<'static, Self>
T, ClassRef<'_, T>, ClassRefMut<'_, T>, ClassPtr<'_, T>, ClassMutPtr<'_, T>作为返回值实质是等价.Source§impl<CharT: AbiType + 'static> Debug for basic_string<CharT>
impl<CharT: AbiType + 'static> Debug for basic_string<CharT>
Source§impl<CharT: AbiType + 'static> Drop for basic_string<CharT>
impl<CharT: AbiType + 'static> Drop for basic_string<CharT>
Source§impl<T: AbiType> PartialEq for basic_string<T>
impl<T: AbiType> PartialEq for basic_string<T>
Source§impl<T: AbiType> PartialOrd for basic_string<T>
impl<T: AbiType> PartialOrd for basic_string<T>
impl<CharT: AbiType + Sync> Send for basic_string<CharT>
impl<CharT: AbiType + Sync> Sync for basic_string<CharT>
Auto Trait Implementations§
impl<CharT> Freeze for basic_string<CharT>where
&'static _Hicc_basic_string_Methods<CharT>: Freeze,
impl<CharT> RefUnwindSafe for basic_string<CharT>where
&'static _Hicc_basic_string_Methods<CharT>: RefUnwindSafe,
impl<CharT> Unpin for basic_string<CharT>where
&'static _Hicc_basic_string_Methods<CharT>: Unpin,
impl<CharT> UnsafeUnpin for basic_string<CharT>where
&'static _Hicc_basic_string_Methods<CharT>: UnsafeUnpin,
impl<CharT> UnwindSafe for basic_string<CharT>where
&'static _Hicc_basic_string_Methods<CharT>: UnwindSafe,
Blanket Implementations§
Source§impl<T> AbiType for Twhere
T: AbiClass,
impl<T> AbiType for Twhere
T: AbiClass,
type InputType = T
type InputPtr<'a, P, const N: usize> = &'a ClassPtr<'a, T, N> where T: 'a
type InputMutPtr<'a, P, const N: usize> = &'a ClassMutPtr<'a, T, N> where T: 'a
type OutputType = T
type OutputRef<'a> = ClassRef<'a, T> where T: 'a
type OutputRefMut<'a> = ClassRefMut<'a, T> where T: 'a
type OutputPtr<'a, P, const N: usize> = ClassPtr<'a, T, N> where T: 'a
type OutputMutPtr<'a, P, const N: usize> = ClassMutPtr<'a, T, N> where T: 'a
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more