pub struct List {
    pub _list: Vec<Object>,
}
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

its implementation

new function

creates a list from another list; like copy constructor

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!

creates a list from string example let list = List::from_string(“q23123123”.to_string()) or let list = List::from_string(String::from(“q23123123”))

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]

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

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.