87 lines
1.8 KiB
Rust
87 lines
1.8 KiB
Rust
use crate::runtime::{
|
|
Variable,
|
|
acquire, release,
|
|
list_capacity, list_length,
|
|
list_at,
|
|
list_clear,
|
|
list_insert, list_update,
|
|
list_remove,
|
|
list_reserve,
|
|
};
|
|
use super::{varying, list};
|
|
|
|
pub struct List {
|
|
managed:bool,
|
|
addr:Variable,
|
|
}
|
|
impl List {
|
|
pub fn new(class:usize) -> Self
|
|
{
|
|
Self {
|
|
managed:true,
|
|
addr:unsafe {acquire(list(class))},
|
|
}
|
|
}
|
|
|
|
pub fn from(addr:Variable) -> Self
|
|
{
|
|
Self { managed:false, addr:addr }
|
|
}
|
|
|
|
pub fn with(data:Vec<Variable>) -> Self
|
|
{
|
|
let mut obj = Self::new(varying());
|
|
for item in data {
|
|
obj.insert(obj.length(), item);
|
|
}
|
|
return obj;
|
|
}
|
|
|
|
pub fn capacity(&self) -> usize
|
|
{
|
|
unsafe {list_capacity(self.addr)}
|
|
}
|
|
|
|
pub fn length(&self) -> usize
|
|
{
|
|
unsafe {list_length(self.addr)}
|
|
}
|
|
|
|
pub fn at(&self, index:usize) -> Variable
|
|
{
|
|
unsafe {list_at(self.addr, index)}
|
|
}
|
|
|
|
pub fn clear(&mut self)
|
|
{
|
|
unsafe{list_clear(self.addr)};
|
|
}
|
|
|
|
pub fn insert(&mut self, index:usize, source:Variable)
|
|
{
|
|
unsafe{list_insert(self.addr, index, source)};
|
|
}
|
|
|
|
pub fn update(&mut self, index:usize, source:Variable)
|
|
{
|
|
unsafe{list_update(self.addr, index, source)};
|
|
}
|
|
|
|
pub fn remove(&mut self, index:usize, maximum:usize)
|
|
{
|
|
unsafe{list_remove(self.addr, index, maximum)};
|
|
}
|
|
|
|
pub fn reserve(&mut self, length:usize)
|
|
{
|
|
unsafe{list_reserve(self.addr, length)};
|
|
}
|
|
}
|
|
impl std::ops::Deref for List {
|
|
type Target = Variable;
|
|
fn deref(&self) -> &Self::Target { return &self.addr; }
|
|
}
|
|
impl Drop for List {
|
|
fn drop(&mut self) { if self.managed { unsafe {release(self.addr)}; } }
|
|
}
|