impl RawValue { /// Get the inner raw RON string, which is guaranteed to contain valid RON. #[must_use] pubfn get_ron(&self) -> &str {
&self.ron
}
/// Helper function to validate a RON string and turn it into a /// [`RawValue`]. pubfn from_ron(ron: &str) -> SpannedResult<&Self> { letmut deserializer = crate::Deserializer::from_str(ron)?;
// raw values can be used everywhere but extensions cannot if !deserializer.extensions().is_empty() { return Err(deserializer.span_error(Error::Message(String::from( "ron::value::RawValue cannot enable extensions",
))));
}
let _ = <&Self>::deserialize(&mut deserializer).map_err(|e| deserializer.span_error(e))?;
/// Helper function to validate a RON string and turn it into a /// [`RawValue`]. pubfn from_boxed_ron(ron: Box<str>) -> SpannedResult<Box<Self>> { matchSelf::from_ron(&ron) {
Ok(_) => Ok(Self::from_boxed_str(ron)),
Err(err) => Err(err),
}
}
/// Helper function to deserialize the inner RON string into `T`. pubfn into_rust<'de, T: Deserialize<'de>>(&'de self) -> SpannedResult<T> {
Options::default().from_str(&self.ron)
}
/// Helper function to serialize `value` into a RON string. pubfn from_rust<T: Serialize>(value: &T) -> Result<Box<Self>, Error> { let ron = Options::default().to_string(value)?;
impl RawValue { #[must_use] /// Trims any leadning and trailing whitespace off the raw RON string, /// including whitespace characters and comments. pubfn trim(&self) -> &Self { Self::from_borrowed_str(&self.ron[RawValue::trim_range(&n style='color:red'>self.ron)])
}
#[must_use] #[allow(unsafe_code)] /// Trims any leadning and trailing whitespace off the boxed raw RON string, /// including whitespace characters and comments. pubfn trim_boxed(self: Box<Self>) -> Box<Self> { let trim_range = RawValue::trim_range(&self.ron); letmut boxed_ron = RawValue::into_boxed_str(self).into_string(); // SAFETY: ron[trim_range] is a valid str, so draining everything // before and after leaves a valid str unsafe {
boxed_ron.as_mut_vec().drain(trim_range.end..);
boxed_ron.as_mut_vec().drain(0..trim_range.start);
}
RawValue::from_boxed_str(boxed_ron.into_boxed_str())
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.