You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: to_numpy.rs
    path of file: ./repos/polars/py-polars/src
    
    the code of the file until where you have to start completion: use std::ffi::{c_int, c_void};

use ndarray::{Dim, Dimension, IntoDimension};
use numpy::npyffi::{flags, PyArrayObject};
use numpy::{npyffi, Element, IntoPyArray, ToNpyDims, PY_ARRAY_API};
use polars_core::prelude::*;
use polars_core::utils::try_get_supertype;
use polars_core::with_match_physical_numeric_polars_type;
use pyo3::prelude::*;

use crate::conversion::Wrap;
use crate::dataframe::PyDataFrame;
use crate::series::PySeries;

pub(crate) unsafe fn create_borrowed_np_array<T: NumericNative + Element, I>(
    py: Python,
    mut shape: Dim<I>,
    flags: c_int,
    data: *mut c_void,
    owner: PyObject,
) -> PyObject
where
    Dim<I>: Dimension + ToNpyDims,
{
    // See: https://numpy.org/doc/stable/reference/c-api/array.html
    let array = PY_ARRAY_API.PyArray_NewFromDescr(
        py,
        PY_ARRAY_API.get_type_object(py, npyffi::NpyTypes::PyArray_Type),
        T::get_dtype(py).into_dtype_ptr(),
        shape.ndim_cint(),
        shape.as_dims_ptr(),
        // We don't provide strides, but provide flags that tell c/f-order
        std::ptr::null_mut(),
        data,
        flags,
     
    
    pub fn to_numpy_view(&self, py: Python) -> Option<PyObject> {
        // NumPy arrays are always contiguous
        if self.series.n_chunks() > 1 {
            return None;
        }

        match self.series.dtype() {
            dt if dt.is_numeric() => {
                let dims = [self.series.len()].into_dimension();
                // Object to the series keep the memory alive.
                let owner = self.clone().into_py(py);
                with_match_physical_numeric_polars_type!(self.series.dtype(), |$T| {
                    let ca: &ChunkedArray<$T> = self.series.unpack::<$T>().unwrap();
                    let slice = ca.data_views().next().unwrap();
                    let view = unsafe {
                        create_borrowed_np_array::<<$T as PolarsNumericType>::Native, _>(
                            py,
                            dims,
                            flags::NPY_ARRAY_FARRAY_RO,
                            slice.as_ptr() as _,
                            owner,
                        )
                    };
                    Some(view)
                })
            },
            _ => None,
        }
    }