From 1920e03371456f52f2f549040e482a8ce713db67 Mon Sep 17 00:00:00 2001 From: Mingun Date: Sat, 19 Oct 2024 10:11:58 +0500 Subject: [PATCH] Implement From and From> for quick_xml::de::Text --- Changelog.md | 2 ++ src/de/mod.rs | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/Changelog.md b/Changelog.md index a75aa465..848d62cc 100644 --- a/Changelog.md +++ b/Changelog.md @@ -15,6 +15,8 @@ ### New Features +- [#826]: Implement `From` and `From>` for `quick_xml::de::Text`. + ### Bug Fixes - [#655]: Do not write indent before and after `$text` fields and those `$value` fields diff --git a/src/de/mod.rs b/src/de/mod.rs index eca85b92..052c4a54 100644 --- a/src/de/mod.rs +++ b/src/de/mod.rs @@ -2067,6 +2067,22 @@ impl<'a> From<&'a str> for Text<'a> { } } +impl<'a> From for Text<'a> { + #[inline] + fn from(text: String) -> Self { + Self { + text: Cow::Owned(text), + } + } +} + +impl<'a> From> for Text<'a> { + #[inline] + fn from(text: Cow<'a, str>) -> Self { + Self { text } + } +} + //////////////////////////////////////////////////////////////////////////////////////////////////// /// Simplified event which contains only these variants that used by deserializer