-
Notifications
You must be signed in to change notification settings - Fork 145
Expand file tree
/
Copy pathstruct_.rs
More file actions
39 lines (34 loc) · 1.08 KB
/
struct_.rs
File metadata and controls
39 lines (34 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright the Vortex contributors
use pyo3::IntoPyObject;
use pyo3::Py;
use pyo3::PyAny;
use pyo3::PyRef;
use pyo3::pyclass;
use pyo3::pymethods;
use vortex::error::vortex_err;
use vortex::scalar::StructScalar;
use crate::PyVortex;
use crate::error::PyVortexResult;
use crate::scalar::AsScalarRef;
use crate::scalar::PyScalar;
use crate::scalar::ScalarSubclass;
/// Concrete class for struct scalars.
#[pyclass(name = "StructScalar", module = "vortex", extends=PyScalar, frozen)]
pub(crate) struct PyStructScalar;
impl ScalarSubclass for PyStructScalar {
type Scalar<'a> = StructScalar<'a>;
}
#[pymethods]
impl PyStructScalar {
/// Return the child scalar with the given field name.
pub fn field(self_: PyRef<'_, Self>, name: &str) -> PyVortexResult<Py<PyAny>> {
let scalar = self_.as_scalar_ref();
let child = scalar
.field(name)
.ok_or_else(|| vortex_err!("No field {name}"))?;
Ok(PyVortex(&child)
.into_pyobject(self_.py())
.map(|v| v.into())?)
}
}