使用 public 命名空间 quick_xml::se 时出错
Error while using public namespace quick_xml::se
我正在尝试使用 quick_xml::se::to_string
函数。这似乎是一个 public 函数,因为它是 in the publicly available docs, is marked as pub in the quick_xml
sources, and seems to work fine in the quick_xml
unit tests。这是我的代码:
use quick_xml::se::to_string as xml_to_string;
use serde::{Serialize};
#[derive(Debug, Serialize, Clone)]
struct ApiError<'a> {
code: &'a str,
}
fn main() {
xml_to_string(ApiError { code: "foo" })
}
然而,这失败了
error[E0432]: unresolved import `quick_xml::se`
--> src/main.rs:1:16
|
1 | use quick_xml::se::to_string as xml_to_string;
| ^^ could not find `se` in `quick_xml`
我尝试了其他几种导入此函数的方法(use quick_xml;
、use quick_xml::se::to_string
),但似乎无论如何,我都会遇到同样的错误。这是怎么回事?
要使用 quick-xml
的 se
模块,您需要启用 serialize
功能。
# Before:
# quick-xml = "0.20.0"
# After:
quick-xml = { version = "0.20", features = ["serialize"] }
如果您向下滚动到“Serde”,quick-xml
的自述文件中会提到这一点。 “功能”.
下的文档中也提到了它
此外,quick_xml::se::to_string()
需要引用您需要添加 &
,例如:
fn main() {
xml_to_string(&ApiError { code: "foo" });
}
我正在尝试使用 quick_xml::se::to_string
函数。这似乎是一个 public 函数,因为它是 in the publicly available docs, is marked as pub in the quick_xml
sources, and seems to work fine in the quick_xml
unit tests。这是我的代码:
use quick_xml::se::to_string as xml_to_string;
use serde::{Serialize};
#[derive(Debug, Serialize, Clone)]
struct ApiError<'a> {
code: &'a str,
}
fn main() {
xml_to_string(ApiError { code: "foo" })
}
然而,这失败了
error[E0432]: unresolved import `quick_xml::se`
--> src/main.rs:1:16
|
1 | use quick_xml::se::to_string as xml_to_string;
| ^^ could not find `se` in `quick_xml`
我尝试了其他几种导入此函数的方法(use quick_xml;
、use quick_xml::se::to_string
),但似乎无论如何,我都会遇到同样的错误。这是怎么回事?
要使用 quick-xml
的 se
模块,您需要启用 serialize
功能。
# Before:
# quick-xml = "0.20.0"
# After:
quick-xml = { version = "0.20", features = ["serialize"] }
如果您向下滚动到“Serde”,quick-xml
的自述文件中会提到这一点。 “功能”.
此外,quick_xml::se::to_string()
需要引用您需要添加 &
,例如:
fn main() {
xml_to_string(&ApiError { code: "foo" });
}