Skip to content

Commit a4536aa

Browse files
Jonathan Bastien-Filiatraultkornelski
authored andcommitted
Have a way to "destructure" a Utf8StringRef.
I need to consume the Utf8StringRef while returning the internal reference for lifetime reasons. Using as_str makes it look like it is borrowing from the Utf8StringRef instead of the source. Sorry for the API breakage on into_str, if you want I can rename the new method into_borrowed_str or something.
1 parent 23ef747 commit a4536aa

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

rmpv/src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,10 +347,15 @@ impl<'a> Utf8StringRef<'a> {
347347
}
348348

349349
/// Consumes this object, yielding the string if the string is valid UTF-8, or else `None`.
350-
pub fn into_str(self) -> Option<String> {
350+
pub fn into_string(self) -> Option<String> {
351351
self.s.ok().map(|s| s.into())
352352
}
353353

354+
/// Consumes this object, yielding the string reference if the string is valid UTF-8, or else `None`.
355+
pub fn into_str(self) -> Option<&'a str> {
356+
self.s.ok()
357+
}
358+
354359
/// Converts a `Utf8StringRef` into a byte vector.
355360
pub fn into_bytes(self) -> Vec<u8> {
356361
match self.s {

0 commit comments

Comments
 (0)