Skip to main content

OsFunctionCall

Enum OsFunctionCall 

Source
pub enum OsFunctionCall {
Show 23 variants Exists(MontyPath), IsFile(MontyPath), IsDir(MontyPath), IsSymlink(MontyPath), ReadText(MontyPath), ReadBytes(MontyPath), Stat(MontyPath), Iterdir(MontyPath), Resolve(MontyPath), Absolute(MontyPath), WriteText(PathStringDataArgs), AppendText(PathStringDataArgs), WriteBytes(PathBytesDataArgs), AppendBytes(PathBytesDataArgs), Open(OpenCallArgs), Mkdir(MkdirCallArgs), Unlink(MontyPath), Rmdir(MontyPath), Rename(RenameCallArgs), Getenv(GetenvArgs), GetEnviron, DateToday, DateTimeNow(Option<MontyTimeZone>),
}
Expand description

Tagged dispatch value for OS-level operations.

Each variant carries the strongly-typed args/kwargs the corresponding OS call needs. The fs/ layer matches on this enum directly (no MontyObject introspection); host bindings get a generic (positional, keyword) view via OsFunctionCall::to_args.

See the module docs for how to add a new variant.

Variants§

§

Exists(MontyPath)

Check if a path exists.

§

IsFile(MontyPath)

Check if path is a regular file.

§

IsDir(MontyPath)

Check if path is a directory.

Check if path is a symbolic link.

§

ReadText(MontyPath)

Read file contents as text.

§

ReadBytes(MontyPath)

Read file contents as bytes.

§

Stat(MontyPath)

stat() — return a stat result tuple.

§

Iterdir(MontyPath)

List directory contents.

§

Resolve(MontyPath)

Resolve symlinks and return absolute path.

§

Absolute(MontyPath)

Absolute path without symlink resolution.

§

WriteText(PathStringDataArgs)

Write text to file (truncating).

§

AppendText(PathStringDataArgs)

Append text to file.

§

WriteBytes(PathBytesDataArgs)

Write bytes to file (truncating).

§

AppendBytes(PathBytesDataArgs)

Append bytes to file.

§

Open(OpenCallArgs)

Open a file. The host performs the open-time effect (truncate for w/w+, create-if-missing for a/a+, existence check for r/r+) and returns a MontyObject::FileHandle — it never holds a live OS handle across calls.

§

Mkdir(MkdirCallArgs)

Create directory (parents/exist_ok kwargs).

Remove file.

§

Rmdir(MontyPath)

Remove directory.

§

Rename(RenameCallArgs)

Rename / move (src → dst).

§

Getenv(GetenvArgs)

Get an environment variable value.

§

GetEnviron

Get the entire environment as a dictionary.

§

DateToday

Get today’s date from the host system (for date.today()).

§

DateTimeNow(Option<MontyTimeZone>)

Get the current date/time from the host system (for datetime.now(tz=...)). Carries the timezone argument, None for a naive result.

Implementations§

Source§

impl OsFunctionCall

Source

pub fn name(&self) -> &'static str

Stable string name for this OS function — surfaces in Self::on_no_handler errors, host os callbacks, and serialised snapshots. The strum serialize string on each variant.

Source

pub fn to_args(self) -> (Vec<MontyObject>, Vec<(MontyObject, MontyObject)>)

Projects this call’s args into (positional, keyword) MontyObject vectors for delivery to a host callback.

Source

pub fn is_write(&self) -> bool

Whether this call mutates filesystem state — the read-only-mount gate. Open’s write-ness is mode-dependent (w/w+/a/a+ write; r/r+ don’t).

Source

pub fn is_existence_check(&self) -> bool

Whether this operation checks existence without reading content. Existence checks return false for nonexistent paths rather than raising FileNotFoundError, matching CPython’s pathlib.Path.

Source

pub fn embedded_null_message(&self, for_destination: bool) -> &'static str

CPython’s ValueError message for a path containing a null byte.

The wording is not uniform in CPython: it comes from whichever layer first inspects the path, so the content operations go through open() and say embedded null byte, while the metadata ones are named by the syscall their os wrapper was about to make. for_destination picks the rename argument that carried the byte.

Source

pub fn fs_primary_path(&self) -> Option<&str>

The call’s primary path if it’s a FS operation, None otherwise.

Used for routing and error reporting.

Source

pub fn rename_destination(&self) -> Option<&str>

The rename destination path, or None for every other variant — the second routing key a mount table needs (both rename endpoints must resolve to the same mount).

Source

pub fn on_no_handler(&self) -> MontyException

Exception to raise when no handler accepted this call: PermissionError for FS ops (with the path), RuntimeError for non-FS ops.

Trait Implementations§

Source§

impl Clone for OsFunctionCall

Source§

fn clone(&self) -> OsFunctionCall

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for OsFunctionCall

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for OsFunctionCall

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for OsFunctionCall

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'_derivative_strum> From<&'_derivative_strum OsFunctionCall> for &'static str

Source§

fn from(x: &'_derivative_strum OsFunctionCall) -> &'static str

Converts to this type from the input type.
Source§

impl From<OsFunctionCall> for &'static str

Source§

fn from(x: OsFunctionCall) -> &'static str

Converts to this type from the input type.
Source§

impl Serialize for OsFunctionCall

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.