forward_list

Struct forward_list 

Source
pub struct forward_list<T: AbiType + 'static> { /* private fields */ }
Expand description

cpp class: template<class T, class Allocator> std::forward_list<T, Allocator>

Implementations§

Source§

impl<T: AbiType + 'static> forward_list<T>

Source

pub fn pop_front(&mut self)

如果为空则忽略.

use hicc_std::ForwardListInt;
let mut list = ForwardListInt::new();
list.push_front(&1);
list.pop_front();
assert!(list.is_empty());
Source

pub fn front(&self) -> Option<T::OutputRef<'_>>

use hicc_std::ForwardListInt;
let mut list = ForwardListInt::new();
list.push_front(&1);
assert_eq!(list.front(), Some(&1));
Source

pub fn front_mut(&mut self) -> Option<T::OutputRefMut<'_>>

use hicc_std::ForwardListInt;
let mut list = ForwardListInt::new();
list.push_front(&1);
*list.front_mut().unwrap() = 2;
assert_eq!(list.front(), Some(&2));

use hicc_std::{string, ForwardListString};
use hicc::AbiClass;
let mut list = ForwardListString::new();
list.push_front(&string::from(c"hello"));
list.front_mut().unwrap().write(string::from(c"world"));
assert_eq!(list.front() , Some(string::from(c"world").into_ref()));
Source

pub fn is_empty(&self) -> bool

use hicc_std::ForwardListInt;
let list = ForwardListInt::new();
assert!(list.is_empty());
Source

pub fn max_size(&self) -> usize

use hicc_std::ForwardListInt;
let mut list = ForwardListInt::new();
list.push_front(&1);
assert!(list.max_size() >= 1);
Source

pub fn clear(&mut self)

use hicc_std::ForwardListInt;
let mut list = ForwardListInt::new();
list.push_front(&1);
list.clear();
assert!(list.is_empty());
Source

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

use hicc_std::ForwardListInt;
let mut list = ForwardListInt::new();
list.resize(10, &1);
assert_eq!(list.iter().count(), 10);
list.iter().for_each(|v| { println!("{v}"); });
Source

pub fn push_front(&mut self, val: &<T as AbiType>::InputType)

use hicc_std::ForwardListInt;
let mut list = ForwardListInt::new();
list.push_front(&1);
assert_eq!(list.front(), Some(&1));
Source

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

use hicc_std::ForwardListInt;
let mut list = ForwardListInt::new();
list.push_front(&1);
list.swap(&mut ForwardListInt::new());
assert!(list.is_empty());
Source

pub fn assign(&mut self, ncount: usize, val: &<T as AbiType>::InputType)

use hicc_std::ForwardListInt;
let mut list = ForwardListInt::new();
list.assign(10, &1);
assert_eq!(list.iter().count(), 10);
assert_eq!(list.front(), Some(&1));
list.iter().for_each(|v| { assert_eq!(v, &1); });
Source

pub fn reverse(&mut self)

use hicc_std::ForwardListInt;
let mut list = ForwardListInt::new();
list.push_front(&2);
list.push_front(&1);
assert_eq!(list.front(), Some(&1));
list.reverse();
assert_eq!(list.front(), Some(&2));
list.iter().for_each(|v| { println!("{v}"); });
Source

pub fn remove(&mut self, val: &<T as AbiType>::InputType)

use hicc_std::ForwardListInt;
let mut list = ForwardListInt::new();
list.push_front(&1);
list.push_front(&2);
list.push_front(&1);
list.remove(&1);
assert_eq!(list.iter().count(), 1);
assert_eq!(list.front(), Some(&2));
Source

pub fn remove_if<'a>(&'a mut self, pred: Function<fn(&'a T::InputType) -> bool>)

cpp global function: void SelfMethods::remove_if(Self&, std::function<bool(const T&)>)

use hicc_std::ForwardListInt;
let mut list = ForwardListInt::new();
list.push_front(&1);
list.push_front(&2);
list.push_front(&3);
list.remove_if(|v: &i32| -> bool {
    (v & 1) == 1
    }.into());
assert_eq!(list.iter().count(), 1);
assert_eq!(list.front(), Some(&2));
Source

pub fn sort<'a>( &'a mut self, comp: Function<fn(&'a T::InputType, &'a T::InputType) -> bool>, )

cpp global function: void SelfMethods::sort(Self&, std::function<bool(const T&, const T&)>)

use hicc_std::ForwardListInt;
let mut list = ForwardListInt::new();
list.push_front(&1);
list.push_front(&2);
list.push_front(&3);
assert_eq!(list.front(), Some(&3));
list.sort(|v1: &i32, v2: &i32| -> bool {
    v1 < v2
    }.into());
let mut it = list.iter();
assert_eq!(it.next(), Some(&1));
assert_eq!(it.next(), Some(&2));
assert_eq!(it.next(), Some(&3));
assert_eq!(it.next(), None);
Source

pub fn merge<'a>( &'a mut self, other: &mut <forward_list<T> as AbiType>::InputType, comp: Function<fn(&'a T::InputType, &'a T::InputType) -> bool>, )

cpp global function: void SelfMethods::merge(Self&, Self&, std::function<bool(const T&, const T&)>) 如果不满足如下条件则忽略.

  1. self.get_allocator() == other.get_allocator().
use hicc_std::ForwardListInt;
let mut list = ForwardListInt::new();
list.push_front(&1);
list.push_front(&3);
let cmp = |v1: &i32, v2: &i32| -> bool {
    v1 < v2
    };
list.sort(cmp.clone().into());
let mut other = ForwardListInt::new();
other.push_front(&2);
other.push_front(&4);
other.sort(cmp.clone().into());
list.merge(&mut other, cmp.into());
let mut it = list.iter();
assert!(other.is_empty());
assert_eq!(it.next(), Some(&1));
assert_eq!(it.next(), Some(&2));
assert_eq!(it.next(), Some(&3));
assert_eq!(it.next(), Some(&4));
assert_eq!(it.next(), None);
Source

pub fn unique_with<'a>( &'a mut self, comp: Function<fn(&'a T::InputType, &'a T::InputType) -> bool>, )

cpp global function: void SelfMethods::unique(Self&, std::function<bool(const T&, const T&)>)

use hicc_std::ForwardListInt;
let mut list = ForwardListInt::new();
list.push_front(&3);
list.push_front(&3);
list.push_front(&1);
list.push_front(&1);
let mut n = 0;
list.unique_with(|v1: &i32, v2: &i32| -> bool {
    v1 == v2
}.into());
let mut it = list.iter();
assert_eq!(it.next(), Some(&1));
assert_eq!(it.next(), Some(&3));
assert_eq!(it.next(), None);
Source

pub fn unique(&mut self)

use hicc_std::ForwardListInt;
let mut list = ForwardListInt::new();
list.push_front(&3);
list.push_front(&3);
list.push_front(&1);
list.push_front(&1);
list.unique();
let mut it = list.iter();
assert_eq!(it.next(), Some(&1));
assert_eq!(it.next(), Some(&3));
assert_eq!(it.next(), None);
Source

pub fn insert_front(&mut self, ncount: usize, val: &<T as AbiType>::InputType)

cpp global function: void insert_after(Self&, size_t, const T&)

use hicc_std::ForwardListInt;
let mut list = ForwardListInt::new();
list.insert_front(2, &1);
let mut it = list.iter();
assert_eq!(it.next(), Some(&1));
assert_eq!(it.next(), Some(&1));
assert_eq!(it.next(), None);
Source

pub fn splice_front( &mut self, other: &mut <forward_list<T> as AbiType>::InputType, )

cpp global function: void splice_after(Self&, Self&) 不满足下面条件则不做任何修改:

  1. self.get_allocator() == other.get_allocator()
  2. &self != &other
use hicc_std::ForwardListInt;
let mut src = ForwardListInt::new();
src.push_front(&1);
src.push_front(&2);
let mut dst = ForwardListInt::new();
dst.splice_front(&mut src);
assert!(src.is_empty());
let mut it = dst.iter();
assert_eq!(it.next(), Some(&2));
assert_eq!(it.next(), Some(&1));
assert_eq!(it.next(), None);
Source§

impl<T: AbiType> forward_list<T>

Source

pub fn iter(&self) -> ForwardListIter<'_, T>

use hicc_std::ForwardListInt;
let mut list = ForwardListInt::new();
list.push_front(&1);
list.push_front(&2);
let mut it = list.iter();
assert_eq!(it.next(), Some(&2));
assert_eq!(it.next(), Some(&1));
assert_eq!(it.next(), None);
Source

pub fn iter_mut(&mut self) -> ForwardListIterMut<'_, T>

use hicc_std::ForwardListInt;
let mut list = ForwardListInt::new();
list.push_front(&1);
list.iter_mut().for_each(|v| *v -= 1);
assert_eq!(list.front(), Some(&0));

Trait Implementations§

Source§

impl<T: AbiType + 'static> AbiClass for forward_list<T>

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<T: AbiType + 'static> Debug for forward_list<T>

Source§

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

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

impl<T: AbiType + 'static> Drop for forward_list<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T: AbiType + Sync> Send for forward_list<T>

Source§

impl<T: AbiType + Sync> Sync for forward_list<T>

Auto Trait Implementations§

§

impl<T> Freeze for forward_list<T>

§

impl<T> RefUnwindSafe for forward_list<T>

§

impl<T> Unpin for forward_list<T>

§

impl<T> UnwindSafe for forward_list<T>

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.