len

Function len 

Source
pub fn len<T>(obj: &T) -> usize
where T: Len,
Expand description

Python len() function - returns the length of an object

Examples found in repository?
examples/std_vs_nostd.rs (line 31)
4fn main() {
5    use stdpython::*;
6    
7    println!("=== STD MODE EXAMPLE ===");
8    
9    // Standard I/O operations available
10    print("Hello from std mode!");
11    
12    // File operations available
13    match open("example.txt", Some("w")) {
14        Ok(mut file) => {
15            let _ = file.write("Hello, file system!");
16            let _ = file.close();
17            println!("File operations work in std mode");
18        },
19        Err(e) => println!("File error: {}", e),
20    }
21    
22    // All core functions work the same
23    let nums = vec![1, 2, 3, 4, 5];
24    println!("sum([1,2,3,4,5]) = {}", sum(&nums[..]));
25    println!("abs(-42) = {}", abs(-42i64));
26    println!("str(true) = '{}'", str(true));
27    
28    // Collections work
29    let mut list = PyList::from_vec(vec![10, 20, 30]);
30    list.append(40);
31    println!("PyList after append: len = {}", len(&list));
32    
33    println!("=== PyO3 and python-mod integration available ===");
34}
More examples
Hide additional examples
examples/generic_api_demo.rs (line 24)
3fn main() {
4    // Demonstrate generic abs function
5    println!("abs(-5i64) = {}", abs(-5i64));
6    println!("abs(-3.14f64) = {}", abs(-3.14f64));
7    
8    // Demonstrate generic sum function
9    let nums = vec![1, 2, 3, 4, 5];
10    println!("sum([1,2,3,4,5]) = {}", sum(&nums[..]));
11    
12    let pylist = PyList::from_vec(vec![10, 20, 30]);
13    println!("sum(PyList([10,20,30])) = {}", sum(&pylist));
14    
15    // Demonstrate generic type conversions
16    println!("str(123) = '{}'", str(123i64));
17    println!("str(true) = '{}'", str(true));
18    println!("bool(42) = {}", bool(42i64));
19    println!("bool('') = {}", bool(""));
20    
21    // Show that single function names match Python exactly
22    println!("\n=== Python-style API ===");
23    let my_string = PyStr::new("Hello World");
24    println!("len('Hello World') = {}", len(&my_string));
25    println!("bool('Hello World') = {}", bool(&my_string));
26    
27    let empty_list: PyList<i32> = PyList::new();
28    println!("bool([]) = {}", bool(&empty_list));
29    
30    let numbers = vec![5, 1, 9, 3];
31    println!("min([5,1,9,3]) = {:?}", min(&numbers));
32    println!("max([5,1,9,3]) = {:?}", max(&numbers));
33}