<jupyter_start><jupyter_text>Integer- Every interger type in rust (`i64, i32, u64, u32, isize, usize`) is compatible with python `int`.- Functions with interger arguments may raise `OverflowError` because python's `int` is bignum.<jupyter_code>%%rustdef
use pyo3::types::PyInt;

#[pyfunction]
fn integer(int64: i64, int32: i32, uint64: u64, uint32: u32, int_size: isize, uint_size: usize, py_int: &PyInt) -> (i64, i32, u64, u32, isize, usize) {
    dbg!(int64);
    dbg!(int32);
    dbg!(uint64);
    dbg!(uint32);
    dbg!(int_size);
    dbg!(uint_size);
    dbg!(py_int);
    (int64 + 1, int32 + 1, uint64 + 1, uint32 + 1, int_size + 1, uint_size + 1)
}
integer(1, 1, 1, 1, 1, 1, 1)
should_raise(OverflowError, integer, (-1, -1, -1, -1, -1, -1, -1))
integer(-1, -1, 0, 0, -1, 0, -1)
x = int(1e10)
should_raise(OverflowError, integer, (x, x, x, x, x, x, x))
x = int(10**10)
y = integer(x, 0, x, 0, x, x, x)
y
x = int(10**30)
y = integer(0, 0, 0, 0, 0, 0, x)
y, list(type(z) for z in y)<jupyter_output>[rustdef_cell_375831073c4f95b3af097c1645d99649dacef238/src/lib.rs:12] int64 = 0
[rustdef_cell_375831073c4f95b3af097c1645d99649dacef238/src/lib.rs:13] int32 = 0
[rustdef_cell_375831073c4f95b3af097c1645d99649dacef238/src/lib.rs:14] uint64 = 0
[rustdef_cell_375831073c4f95b3af097c1645d99649dacef238/src/lib.rs:15] uint32 = 0
[rustdef_cell_375831073c4f95b3af097c1645d99649dacef238/src/lib.rs:16] int_size = 0
[rustdef_cell_375831073c4f95b3af097c1645d99649dacef238/src/lib.rs:17] uint_size = 0
[rustdef_cell_375831073c4f95b3af097c1645d99649dacef238/src/lib.rs:18] py_int = 1000000000000000000000000000000<jupyter_text>Float- rust's `f64` and `f32` are compatible with python's `float`<jupyter_code>%%rustdef --force-rebuild

#[pyfunction]
fn floating(double: f64, float: f32) -> (f64, f32) {
    dbg!(double);
    dbg!(float);
    (double, float)
}
y = floating(0.3, 0.3)
y
type(y[0]), type(y[1])<jupyter_output><empty_output><jupyter_text>String- Rust's `String` and `&str` are compatible to python's `str`- Strings are immutable<jupyter_code>%%rustdef

#[pyfunction]
fn strings(x: String, y: &str) -> (String, &str) {
    dbg!(&x);
    dbg!(y);
    
    (x, y)
}
y = strings("foo", "bar")
y
type(y[0]), type(y[1])<jupyter_output><empty_output><jupyter_text>List- Python's `list` can be converted to rust's `Vec`, and vise versa.- To mutate python `list`, it should be passed as `&PyList` (`&mut` is redundant)    - see https://pyo3.rs/master/doc/pyo3/types/struct.PyList.html<jupyter_code>%%rustdef --force-rebuild
use pyo3::types::PyList;

#[pyfunction]
fn lists(x: Vec<i64>, y: Vec<String>, z: &PyList) -> PyResult<Vec<(i64, String)>> {
    dbg!(&x);
    dbg!(&y);
    dbg!(z);
    
    z.append("foo")?;
    Ok(x.into_iter().zip(y.into_iter()).collect())
}
x = ["bar", 9]
lists([1, 2, 3], ["a", "b"], x), x
should_raise(TypeError, lists, ([1, 2, 3], ["a", 2], []))<jupyter_output><jupyter_text>Dict- python `dict` can be converted to `HashMap`, and vise versa.}- To mutate `dict`, it should be passed as `&PyDict`    - see https://pyo3.rs/master/doc/pyo3/types/struct.PyDict.html<jupyter_code>%%rustdef
use std::collections::HashMap;
use pyo3::types::PyDict;

#[pyfunction]
fn dicts(x: HashMap<String, i64>, y: HashMap<i64, Vec<i64>>, z: &PyDict) -> PyResult<()> {
    dbg!(&x);
    dbg!(&y);
    dbg!(z);
    
    z.set_item("10", 11)?;
    Ok(())
}
x = {"foo": []}
dicts(dict(x=10, y=-4), {1: [2, 3], 4: [], 5:[6]}, x)
x
should_raise(TypeError, dicts, (dict(x=10, y="-4"), dict(), dict()))<jupyter_output>'str' object cannot be interpreted as an integer
{'fraction_non_alphanumeric': 0.1897666572954737, 'fraction_numerical': 0.11526567332021366, 'mean_word_length': 5.030508474576271, 'pattern_counts': {'":': 1, '<': 26, '<?xml version=': 0, '>': 31, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '97539', 'license': 'MIT', 'n_tokens_mistral': 1798, 'n_tokens_neox': 1546, 'n_words': 340, 'path': 'examples/types.ipynb', 'repo_name': 'emakryo/rustdef', 'size': '3557'}