Struct PyFile

Source
pub struct PyFile { /* private fields */ }
Expand description

Python file object

Note: Only available with std feature - requires OS I/O capabilities

Implementations§

Source§

impl PyFile

Source

pub fn read(&mut self) -> Result<String, PyException>

Python file.read() method

Source

pub fn readline(&mut self) -> Result<String, PyException>

Python file.readline() method

Source

pub fn readlines(&mut self) -> Result<Vec<String>, PyException>

Python file.readlines() method

Source

pub fn write<D: AsRef<str>>(&mut self, data: D) -> Result<usize, PyException>

Python file.write() method

Examples found in repository?
examples/std_vs_nostd.rs (line 15)
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}
Source

pub fn writelines<S: AsRef<str>>( &mut self, lines: &[S], ) -> Result<(), PyException>

Python file.writelines() method

Source

pub fn close(&mut self) -> Result<(), PyException>

Python file.close() method

Examples found in repository?
examples/std_vs_nostd.rs (line 16)
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}

Auto Trait Implementations§

§

impl Freeze for PyFile

§

impl RefUnwindSafe for PyFile

§

impl Send for PyFile

§

impl Sync for PyFile

§

impl Unpin for PyFile

§

impl UnwindSafe for PyFile

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Ungil for T
where T: Send,