rustpython_vm/function/
mod.rs

1mod argument;
2mod arithmetic;
3mod buffer;
4mod builtin;
5mod either;
6mod fspath;
7mod getset;
8mod method;
9mod number;
10mod protocol;
11
12pub use argument::{
13    ArgumentError, FromArgOptional, FromArgs, FuncArgs, IntoFuncArgs, KwArgs, OptionalArg,
14    OptionalOption, PosArgs,
15};
16pub use arithmetic::{PyArithmeticValue, PyComparisonValue};
17pub use buffer::{ArgAsciiBuffer, ArgBytesLike, ArgMemoryBuffer, ArgStrOrBytesLike};
18pub use builtin::{static_func, static_raw_func, IntoPyNativeFn, PyNativeFn};
19pub use either::Either;
20pub use fspath::FsPath;
21pub use getset::PySetterValue;
22pub(super) use getset::{IntoPyGetterFunc, IntoPySetterFunc, PyGetterFunc, PySetterFunc};
23pub use method::{HeapMethodDef, PyMethodDef, PyMethodFlags};
24pub use number::{ArgIndex, ArgIntoBool, ArgIntoComplex, ArgIntoFloat, ArgPrimitiveIndex, ArgSize};
25pub use protocol::{ArgCallable, ArgIterable, ArgMapping, ArgSequence};
26
27use crate::{builtins::PyStr, convert::TryFromBorrowedObject, PyObject, PyResult, VirtualMachine};
28use builtin::{BorrowedParam, OwnedParam, RefParam};
29
30#[derive(Clone, Copy, PartialEq, Eq)]
31pub enum ArgByteOrder {
32    Big,
33    Little,
34}
35
36impl<'a> TryFromBorrowedObject<'a> for ArgByteOrder {
37    fn try_from_borrowed_object(vm: &VirtualMachine, obj: &'a PyObject) -> PyResult<Self> {
38        obj.try_value_with(
39            |s: &PyStr| match s.as_str() {
40                "big" => Ok(Self::Big),
41                "little" => Ok(Self::Little),
42                _ => {
43                    Err(vm.new_value_error("byteorder must be either 'little' or 'big'".to_owned()))
44                }
45            },
46            vm,
47        )
48    }
49}