Skip to content

Replace OnceCell::Lazy with std::sync::LazyLock ? #124

Open
@bionicles

Description

@bionicles

in lib.rs:

use once_cell::sync::Lazy;

pub(crate) static POLARS: Lazy<PyObject> = Lazy::new(|| {
    Python::with_gil(|py| PyModule::import_bound(py, "polars").unwrap().to_object(py))
});

pub(crate) static SERIES: Lazy<PyObject> =
    Lazy::new(|| Python::with_gil(|py| POLARS.getattr(py, "Series").unwrap()));

we could remove this dependency on once_cell by using LazyLock in std::sync

use std::sync::LazyLock;

pub(crate) static POLARS: LazyLock<Py<PyModule>> = LazyLock::new(|| {
    Python::with_gil(|py| {
        let x = PyModule::import(py, "polars").unwrap().unbind();
        x
    })
});

pub(crate) static SERIES: LazyLock<PyObject> =
    LazyLock::new(|| Python::with_gil(|py| POLARS.getattr(py, "Series").unwrap()));

benefit: drops an external dependency on once_cell
downside: may increase MSRV (minimum supported rust version)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions