Expand description
the main component
contens structure of good docs [short sentence explaining what it is]
[more detailed explanation]
[at least one code example that users can copy/paste to try it]
[even more advanced explanations if necessary]
Fields
_list: Vec<Object>
_list which holds all the python objects together
Implementations
sourceimpl List
impl List
its implementation
sourcepub fn from_int(_integer: i32) -> List
pub fn from_int(_integer: i32) -> List
Showcase - python list
// the crate name is 'python-objects'
// because there is another crate out there with `python` name
// but the lib.rs (library crate of this crate) its called `python`
// so you can import like this
extern crate python;
// actually 'extern crate' is useless
// just use only 'use python::'
// use everything from python
use python::*;
fn main() {
// create a new python list from a string
let mut python_list =
List::from_string(String::from("123123"));
// since rust doesnt have function overloading
// we are stuck with different names
// but i think its better because its more explicit
// append some values
python_list.append_int(123);
python_list.append_float(123.123);
python_list.append_float(123.123);
python_list.append_float(123.123);
python_list.append_string(String::from("asdasd"));
// append a rust string
python_list.append_list(
List::from_string("rust's string".to_string()));
// append a python string
python_list.append_pstring(
_String::from_string(
String::from("python string")));
// note the python-like print
// print to stdout
print(&python_list);
// and len
// print length of list
print(len(&python_list));
}
output
['1', '2', '3', '1', '2', '3', 123, 123.123, 123.123, 123.123, 'asdasd', ['a', 'n', 'd', 'r', 'e', 'w'], 'python string']
13
as you can see the list contains char
, float (f32)
, integer (i32)
, a rust string
, another python list
, and a python string
this is just bare bones
and experimental
, more features will come soon. stay still!
sourcepub fn from_string(_string: String) -> List
pub fn from_string(_string: String) -> List
creates a list from string example let list = List::from_string(“q23123123”.to_string()) or let list = List::from_string(String::from(“q23123123”))
sourcepub fn append_int(&mut self, _integer: i32) -> &mut Self
pub fn append_int(&mut self, _integer: i32) -> &mut Self
inline append for integer example
let mut one_elem = List::new(); one_elem .append_int(123) .append_int(123) .append_int(123) .append_int(123) .append_int(123) .append_int(123) .append_int(123); println!(“{}”, one_elem);
[123, 123, 123, 123, 123, 123, 123]
pub fn append_char(&mut self, _char: char) -> &mut Self
pub fn append_float(&mut self, _float: f32) -> &mut Self
pub fn append_string(&mut self, string: String) -> &mut Self
pub fn append_pstring(&mut self, _string: _String) -> &mut Self
pub fn append_list(&mut self, _list: List) -> &mut Self
pub fn append_bool(&mut self, _bool: bool) -> &mut Self
sourcepub fn append_pbool(&mut self, _bool: Bool) -> &mut Self
pub fn append_pbool(&mut self, _bool: Bool) -> &mut Self
append python bool: Bool struct
example
use python::{List, Bool, print};
use pretty_assertions::assert_eq;
let python_bool = Bool::new(true);
let mut python_list = List::new();
python_list.append_pbool(python_bool);
print(python_list);
// assert_eq!(123, 1233);
output
[True]
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for List
impl Send for List
impl Sync for List
impl Unpin for List
impl UnwindSafe for List
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more