basic_string

Struct basic_string 

Source
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>

Source

pub const npos: usize = 18_446_744_073_709_551_615usize

Source

pub fn substr(&self, pos: usize, len: usize) -> Self

如果pos超出范围,会返回空字符串.

use hicc_std::string;
let mut s = string::from(c"abc");
let substr = s.substr(1, 2);
assert_eq!(substr.as_cstr(), c"bc");
Source

pub fn append_str(&mut self, s: &Self, subpos: usize, sublen: usize)

如果subpos超出范围则不做任何改变.

use hicc_std::string;
let mut s1 = string::from(c"abc");
let s2 = string::from(c"def");
s1.append_str(&s2, 0, 2);
assert_eq!(s1.as_cstr(), c"abcde");
Source

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(c"abc");
let mut s2 = string::from(c"def");
s1.insert_str(0, &s2, 0, string::npos);
assert_eq!(s1.as_cstr(), c"defabc");
s1.insert_str(100, &s2, 0, string::npos);
assert_eq!(s1.as_cstr(), c"defabcdef");
Source

pub fn insert(&mut self, pos: usize, n: usize, c: CharT::InputType)

如果pos超出范围则追加到最后.

use hicc_std::string;
let mut s = string::from(c"abc");
s.insert(0, 3, b'd' as i8);
assert_eq!(s.as_cstr(), c"dddabc");
s.insert(110, 3, b'd' as i8);
assert_eq!(s.as_cstr(), c"dddabcddd");
Source

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(c"abc");
let mut s2 = string::from(c"de");
s1.replace_str(0, string::npos, &s2, 0, string::npos);
assert_eq!(s1.as_cstr(), c"de");
Source

pub fn replace(&mut self, pos: usize, len: usize, n: usize, c: CharT::InputType)

如果pos超出范围则不做任何改变.

use hicc_std::string;
let mut s = string::from(c"abc");
s.replace(0, string::npos, 1, b'd' as i8);
assert_eq!(s.as_cstr(), c"d");
Source

pub fn assign_str(&mut self, s: &Self, subpos: usize, sublen: usize)

如果subpos超出范围则不做任何改变.

use hicc_std::string;
let mut s1 = string::from(c"abc");
let mut s2 = string::from(c"de");
s1.assign_str(&s2, 0, string::npos);
assert_eq!(s1.as_cstr(), c"de");
Source

pub fn erase(&mut self, pos: usize, len: usize)

如果pos超出范围则不做任何改变.

use hicc_std::string;
let mut s = string::from(c"abc");
s.erase(1, 1);
assert_eq!(s.as_cstr(), c"ac");
Source

pub fn pop_back(&mut self)

如果为空则不做任何改变.

use hicc_std::string;
let mut s = string::from(c"abc");
s.pop_back();
assert_eq!(s.as_cstr(), c"ab");
Source

pub fn get(&self, pos: usize) -> Option<CharT::OutputRef<'_>>

use hicc_std::string;
let s = string::from(c"abc");
assert_eq!(s.get(0), Some(&(b'a' as i8)));
assert_eq!(s.get(3), None);
Source

pub fn get_mut(&mut self, pos: usize) -> Option<CharT::OutputRefMut<'_>>

use hicc_std::string;
let mut s = string::from(c"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);
Source

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(c"abc");
let cstr = unsafe { CStr::from_ptr(s.c_str()) };
assert_eq!(cstr, c"abc");
Source

pub fn is_empty(&self) -> bool

use hicc_std::string;
let s = string::new();
assert!(s.is_empty());
Source

pub fn size(&self) -> usize

use hicc_std::string;
let s = string::new();
assert_eq!(s.size(), 0);
Source

pub fn max_size(&self) -> usize

use hicc_std::string;
let s = string::new();
println!("s.max_size = {}", s.max_size());
Source

pub fn capacity(&self) -> usize

use hicc_std::string;
let s = string::new();
println!("s.capacity = {}", s.capacity());
Source

pub fn resize(&mut self, n: usize, c: <CharT as AbiType>::InputType)

use hicc_std::string;
let mut s = string::from(c"a");
s.resize(3, b'c' as i8);
assert_eq!(s.as_cstr(), c"acc");
Source

pub fn reserve(&mut self, n: usize)

use hicc_std::string;
let mut s = string::from(c"abc");
s.reserve(100);
println!("s.capacity = {}", s.capacity());
Source

pub fn clear(&mut self)

use hicc_std::string;
let mut s = string::from(c"abc");
s.clear();
assert!(s.is_empty());
Source

pub fn shrink_to_fit(&mut self)

use hicc_std::string;
let mut s = string::from(c"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());
Source

pub fn compare( &self, other: &<basic_string<CharT> as AbiType>::InputType, ) -> i32

use hicc_std::string;
let s1 = string::from(c"abc");
let s2 = string::from(c"abd");
assert!(s1 < s2);
assert!(s1 != s2);
Source

pub fn find_str( &self, target: &<basic_string<CharT> as AbiType>::InputType, pos: usize, ) -> usize

use hicc_std::string;
let s1 = string::from(c"abcdef");
let s2 = string::from(c"bcd");
assert_eq!(s1.find_str(&s2, 0), 1);
Source

pub fn find(&self, c: <CharT as AbiType>::InputType, pos: usize) -> usize

use hicc_std::string;
let s = string::from(c"abcdef");
assert_eq!(s.find(b'c' as i8, 1), 2);
Source

pub fn rfind_str( &self, target: &<basic_string<CharT> as AbiType>::InputType, pos: usize, ) -> usize

use hicc_std::string;
let s1 = string::from(c"abcdef");
let s2 = string::from(c"bcd");
assert_eq!(s1.rfind_str(&s2, string::npos), 1);
Source

pub fn rfind(&self, c: <CharT as AbiType>::InputType, pos: usize) -> usize

use hicc_std::string;
let s = string::from(c"abcdef");
assert_eq!(s.rfind(b'c' as i8, string::npos), 2);
Source

pub fn find_first_of( &self, target: &<basic_string<CharT> as AbiType>::InputType, pos: usize, ) -> usize

use hicc_std::string;
let s1 = string::from(c"abcdef");
let s2 = string::from(c"dfb");
assert_eq!(s1.find_first_of(&s2, 0), 1);
Source

pub fn find_first(&self, c: <CharT as AbiType>::InputType, pos: usize) -> usize

use hicc_std::string;
let s = string::from(c"abcabc");
assert_eq!(s.find_first(b'c' as i8, 0), 2);
Source

pub fn find_last_of( &self, target: &<basic_string<CharT> as AbiType>::InputType, pos: usize, ) -> usize

use hicc_std::string;
let s1 = string::from(c"abcdef");
let s2 = string::from(c"dfb");
assert_eq!(s1.find_last_of(&s2, string::npos), 5);
Source

pub fn find_last(&self, c: <CharT as AbiType>::InputType, pos: usize) -> usize

use hicc_std::string;
let s = string::from(c"abcabc");
assert_eq!(s.find_last(b'c' as i8, string::npos), 5);
Source

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(c"abcdef");
let s2 = string::from(c"abc");
assert_eq!(s1.find_first_not_of(&s2, 0), 3);
Source

pub fn find_first_not( &self, c: <CharT as AbiType>::InputType, pos: usize, ) -> usize

use hicc_std::string;
let s = string::from(c"abcabc");
assert_eq!(s.find_first_not(b'a' as i8, 0), 1);
Source

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(c"abcdef");
let s2 = string::from(c"def");
assert_eq!(s1.find_last_not_of(&s2, string::npos), 2);
Source

pub fn find_last_not( &self, c: <CharT as AbiType>::InputType, pos: usize, ) -> usize

use hicc_std::string;
let s = string::from(c"abcabc");
assert_eq!(s.find_last_not(b'c' as i8, string::npos), 4);
Source

pub fn append(&mut self, n: usize, c: <CharT as AbiType>::InputType)

use hicc_std::string;
let mut s = string::from(c"abc");
s.append(1, b'd' as i8);
assert_eq!(s.as_cstr(), c"abcd");
Source

pub fn assign(&mut self, n: usize, c: <CharT as AbiType>::InputType)

use hicc_std::string;
let mut s = string::from(c"abc");
s.assign(1, b'd' as i8);
assert_eq!(s.as_cstr(), c"d");
Source

pub fn push_back(&mut self, c: <CharT as AbiType>::InputType)

use hicc_std::string;
let mut s = string::from(c"abc");
s.push_back(b'd' as i8);
assert_eq!(s.as_cstr(), c"abcd");
Source

pub fn swap(&mut self, other: &mut <basic_string<CharT> as AbiType>::InputType)

use hicc_std::string;
let mut s1 = string::from(c"abc");
let mut s2 = string::from(c"de");
s1.swap(&mut s2);
assert_eq!(s1.as_cstr(), c"de");
assert_eq!(s2.as_cstr(), c"abc");
Source§

impl<T: Sized + 'static> basic_string<Pod<T>>

Source

pub fn as_slice(&self) -> &[T]

use hicc_std::string;
let mut s = string::with_cstr(c"bcd");
assert_eq!(s.as_slice(), &[b'b' as i8, b'c' as i8, b'd' as i8]);
Source

pub fn as_slice_mut(&mut self) -> &mut [T]

use hicc_std::string;
let mut s = string::with_cstr(c"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>>

Source

pub fn new() -> Self

Source

pub fn with_cstr(s: &CStr) -> Self

Source

pub fn with_buf(b: &[u8]) -> Self

Source

pub fn as_cstr(&self) -> &CStr

Source§

impl basic_string<Pod<i16>>

Source

pub fn new() -> Self

Source

pub fn with_buf(b: &[u16]) -> Self

Source§

impl basic_string<Pod<i32>>

Source

pub fn new() -> Self

Source

pub fn with_buf(b: &[u32]) -> Self

Trait Implementations§

Source§

impl<CharT: AbiType + 'static> AbiClass for basic_string<CharT>

Source§

fn get_raw_obj(&self) -> *const ()

仅内部使用.指针携带附加信息,不能转换为c++类指针.
Source§

unsafe fn make_ref(&self, obj: *const ()) -> Self

Safety Read more
Source§

unsafe fn into_unique(self) -> Self

Safety Read more
Source§

fn write(&mut self, other: Self)

更新对象本身. Read more
Source§

fn size_of(&self) -> usize

返回c++对象的大小.
Source§

fn is_null(&self) -> bool

rust侧的值类型实际都对应到c++侧的对象指针, 检查是否为空指针.
Source§

fn as_ref(&self) -> ClassRef<'_, Self>

T, ClassRef<'_, T>, ClassRefMut<'_, T>, ClassPtr<'_, T>, ClassMutPtr<'_, T>作为返回值实质是等价. Read more
Source§

fn as_mut(&mut self) -> ClassRefMut<'_, Self>

T, ClassRef<'_, T>, ClassRefMut<'_, T>, ClassPtr<'_, T>, ClassMutPtr<'_, T>作为返回值实质是等价. Read more
Source§

fn as_ptr(&self) -> ClassPtr<'_, Self>

T, ClassRef<'_, T>, ClassRefMut<'_, T>, ClassPtr<'_, T>, ClassMutPtr<'_, T>作为返回值实质是等价. Read more
Source§

fn as_mut_ptr(&mut self) -> ClassMutPtr<'_, Self>

AbiType::InputMutPtr<'_, T>参数类型实际是&ClassMutPtr<'_, T>, 当需要传递这类参数时可调用此接口.
Source§

fn into_ref(self) -> ClassRef<'static, Self>

T, ClassRef<'_, T>, ClassRefMut<'_, T>, ClassPtr<'_, T>, ClassMutPtr<'_, T>作为返回值实质是等价.
Source§

fn into_mut(self) -> ClassRefMut<'static, Self>

T, ClassRef<'_, T>, ClassRefMut<'_, T>, ClassPtr<'_, T>, ClassMutPtr<'_, T>作为返回值实质是等价.
Source§

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>

T, ClassRef<'_, T>, ClassRefMut<'_, T>, ClassPtr<'_, T>, ClassMutPtr<'_, T>作为返回值实质是等价.
Source§

fn get_obj(&self) -> *const ()

一般内部使用. 返回值等同于c++侧的指针。
Source§

impl<CharT: AbiType + 'static> Debug for basic_string<CharT>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<CharT: AbiType + 'static> Drop for basic_string<CharT>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T: AbiType> PartialEq for basic_string<T>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: AbiType> PartialOrd for basic_string<T>

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<CharT: AbiType + Sync> Send for basic_string<CharT>

Source§

impl<CharT: AbiType + Sync> Sync for basic_string<CharT>

Auto Trait Implementations§

§

impl<CharT> Freeze for basic_string<CharT>

§

impl<CharT> RefUnwindSafe for basic_string<CharT>

§

impl<CharT> Unpin for basic_string<CharT>

§

impl<CharT> UnwindSafe for basic_string<CharT>

Blanket Implementations§

Source§

impl<T> AbiType for T
where T: AbiClass,

Source§

type InputType = T

Source§

type InputPtr<'a, P, const N: usize> = &'a ClassPtr<'a, T, N> where T: 'a

Source§

type InputMutPtr<'a, P, const N: usize> = &'a ClassMutPtr<'a, T, N> where T: 'a

Source§

type OutputType = T

Source§

type OutputRef<'a> = ClassRef<'a, T> where T: 'a

Source§

type OutputRefMut<'a> = ClassRefMut<'a, T> where T: 'a

Source§

type OutputPtr<'a, P, const N: usize> = ClassPtr<'a, T, N> where T: 'a

Source§

type OutputMutPtr<'a, P, const N: usize> = ClassMutPtr<'a, T, N> where T: 'a

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.