Skip to content
Snippets Groups Projects
Unverified Commit 0becc45b authored by Michal Kucharczyk's avatar Michal Kucharczyk Committed by GitHub
Browse files

sp_runtime: TryFrom<RuntimeString> for &str (#3942)

Added `TryFrom<&'a RuntimeString> for &'a str`
parent 5d9826c2
No related merge requests found
Pipeline #461478 passed with stages
in 1 hour, 10 minutes, and 48 seconds
......@@ -61,6 +61,19 @@ impl From<&'static str> for RuntimeString {
}
}
impl<'a> TryFrom<&'a RuntimeString> for &'a str {
type Error = core::str::Utf8Error;
fn try_from(from: &'a RuntimeString) -> core::result::Result<&'a str, Self::Error> {
match from {
#[cfg(feature = "std")]
RuntimeString::Owned(string) => Ok(string.as_str()),
#[cfg(not(feature = "std"))]
RuntimeString::Owned(vec) => core::str::from_utf8(&vec),
RuntimeString::Borrowed(str) => Ok(str),
}
}
}
#[cfg(feature = "std")]
impl From<RuntimeString> for String {
fn from(string: RuntimeString) -> Self {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment