Skip to main content

rustpython_vm/function/
mod.rs

1mod argument;
2mod arithmetic;
3mod buffer;
4mod builtin;
5mod doctext;
6mod either;
7mod fspath;
8mod getargs;
9mod getset;
10pub(crate) mod method;
11mod number;
12mod protocol;
13mod signature;
14mod time;
15
16pub use argument::{
17    ArgumentError, Callee, FromArgOptional, FromArgs, FuncArgs, IntoFuncArgs, KwArgs, KwArgsMap,
18    NameArgs, NameChanges, NameCoordinates, NameExcInfo, NameFields, NameIntegers, NameIterables,
19    NameKeywords, NameKwargs, NameKwds, NameKws, NameObjs, NameOthers, OptionalArg,
20    OptionalArgDefault, OptionalOption, PosArgs, PositionalIterable,
21};
22pub(crate) use argument::{arity_message, unexpected_keyword_message};
23pub use arithmetic::{PyArithmeticValue, PyComparisonValue};
24pub use buffer::{
25    ArgAsciiBuffer, ArgBytesLike, ArgContiguousBytesLike, ArgMemoryBuffer, ArgStrOrBytesLike,
26};
27pub use builtin::{IntoPyNativeFn, PyNativeFn, static_func, static_raw_func};
28pub use doctext::{ItemDoc, db_doc, plain_doc};
29pub use either::Either;
30pub use fspath::FsPath;
31pub(crate) use getargs::ArgSpec;
32pub use getset::PySetterValue;
33pub(super) use getset::{IntoPyGetterFunc, IntoPySetterFunc, PyGetterFunc, PySetterFunc};
34pub use method::{HeapMethodDef, PyMethodDef, PyMethodFlags};
35pub use number::{
36    ArgIndex, ArgIntoBool, ArgIntoComplex, ArgIntoFloat, ArgStrictInt, PySize, PySsize,
37};
38pub use protocol::{ArgCallable, ArgIterable, ArgMapping, ArgSequence};
39pub use signature::{
40    DefaultRepr, Param, ParamKind, SigArg, choose_class_params, has_signature, internal_doc_bytes,
41    internal_doc_len, real_signature, signature_prefix_bytes, signature_prefix_len,
42};
43pub use time::TimeoutSeconds;
44
45use crate::{
46    Py, PyObject, PyResult, VirtualMachine, builtins::PyStr, convert::TryFromBorrowedObject,
47};
48use builtin::{BorrowedParam, OwnedParam, RefParam};
49
50#[derive(Clone, Copy, PartialEq, Eq)]
51pub enum ArgByteOrder {
52    Big,
53    Little,
54}
55
56impl ArgByteOrder {
57    #[must_use]
58    pub const fn py_default(&self) -> DefaultRepr {
59        match self {
60            Self::Big => DefaultRepr::Str("big"),
61            Self::Little => DefaultRepr::Str("little"),
62        }
63    }
64}
65
66impl<'a> TryFromBorrowedObject<'a> for ArgByteOrder {
67    fn try_from_borrowed_object(vm: &VirtualMachine, obj: &'a PyObject) -> PyResult<Self> {
68        obj.try_value_with(
69            |s: &Py<PyStr>| match s.as_bytes() {
70                b"big" => Ok(Self::Big),
71                b"little" => Ok(Self::Little),
72                _ => Err(vm.new_value_error("byteorder must be either 'little' or 'big'")),
73            },
74            vm,
75        )
76    }
77}