mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-09 22:49:57 +09:00
@@ -16,7 +16,7 @@ use crate::{
|
||||
AsMapping, AsSequence, Comparable, Constructor, Hashable, IterNext, IterNextIterable,
|
||||
Iterable, PyComparisonOp, Unconstructible,
|
||||
},
|
||||
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult,
|
||||
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyRefExact, PyResult,
|
||||
TryFromBorrowedObject, VirtualMachine,
|
||||
};
|
||||
use ascii::{AsciiStr, AsciiString};
|
||||
@@ -116,6 +116,12 @@ impl AsRef<str> for PyStr {
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<str> for Py<PyStr> {
|
||||
fn as_ref(&self) -> &str {
|
||||
self.as_str()
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<str> for PyStrRef {
|
||||
fn as_ref(&self) -> &str {
|
||||
self.as_str()
|
||||
@@ -1510,6 +1516,12 @@ impl SliceableSequenceOp for PyStr {
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<str> for PyRefExact<PyStr> {
|
||||
fn as_ref(&self) -> &str {
|
||||
self.as_str()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
@@ -42,6 +42,7 @@ impl StringPool {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[repr(transparent)]
|
||||
pub struct CachedPyStrRef {
|
||||
inner: PyRefExact<PyStr>,
|
||||
}
|
||||
|
||||
@@ -1001,6 +1001,16 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> AsRef<Py<T>> for PyRef<T>
|
||||
where
|
||||
T: PyObjectPayload,
|
||||
{
|
||||
#[inline(always)]
|
||||
fn as_ref(&self) -> &Py<T> {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Deref for PyRef<T>
|
||||
where
|
||||
T: PyObjectPayload,
|
||||
|
||||
@@ -116,6 +116,13 @@ impl<T: PyPayload> Deref for PyRefExact<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: PyObjectPayload> AsRef<Py<T>> for PyRefExact<T> {
|
||||
#[inline(always)]
|
||||
fn as_ref(&self) -> &Py<T> {
|
||||
self.inner.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: PyPayload> ToPyObject for PyRefExact<T> {
|
||||
#[inline(always)]
|
||||
fn to_pyobject(self, _vm: &VirtualMachine) -> PyObjectRef {
|
||||
|
||||
Reference in New Issue
Block a user