add `AsRef` impls for `PyBackedStr` and `PyBackedBytes` (#3991)
* add `AsRef` impls for `PyBackedStr` and `PyBackedBytes` * add newsfragment
This commit is contained in:
parent
7d319a906e
commit
54ffaecd65
|
@ -0,0 +1 @@
|
||||||
|
implemented `AsRef<str>` and `AsRef<[u8]>` for `PyBackedStr`, `AsRef<[u8]>` for `PyBackedBytes`.
|
|
@ -27,6 +27,18 @@ impl Deref for PyBackedStr {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl AsRef<str> for PyBackedStr {
|
||||||
|
fn as_ref(&self) -> &str {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AsRef<[u8]> for PyBackedStr {
|
||||||
|
fn as_ref(&self) -> &[u8] {
|
||||||
|
self.as_bytes()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl TryFrom<Bound<'_, PyString>> for PyBackedStr {
|
impl TryFrom<Bound<'_, PyString>> for PyBackedStr {
|
||||||
type Error = PyErr;
|
type Error = PyErr;
|
||||||
fn try_from(py_string: Bound<'_, PyString>) -> Result<Self, Self::Error> {
|
fn try_from(py_string: Bound<'_, PyString>) -> Result<Self, Self::Error> {
|
||||||
|
@ -82,6 +94,12 @@ impl Deref for PyBackedBytes {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl AsRef<[u8]> for PyBackedBytes {
|
||||||
|
fn as_ref(&self) -> &[u8] {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl From<Bound<'_, PyBytes>> for PyBackedBytes {
|
impl From<Bound<'_, PyBytes>> for PyBackedBytes {
|
||||||
fn from(py_bytes: Bound<'_, PyBytes>) -> Self {
|
fn from(py_bytes: Bound<'_, PyBytes>) -> Self {
|
||||||
let b = py_bytes.as_bytes();
|
let b = py_bytes.as_bytes();
|
||||||
|
|
Loading…
Reference in New Issue