`from_xml` not found
ZJaume opened this issue · comments
Trying to compile the example in the documentation but it doesn't compile despite from_xml
feature being enabled.
use std::fs;
use srx::SRX;
fn main() {
let srx = SRX::from_xml(&fs::read_to_string("data/language_tools.segment.srx").unwrap())?;
let english_rules = srx.language_rules("en");
println!("Hello, world!");
assert_eq!(
english_rules.split("e.g. U.K. and Mr. do not split. SRX is a rule-based format.").collect::<Vec<_>>(),
vec!["e.g. U.K. and Mr. do not split. ", "SRX is a rule-based format."]
);
}
error[E0599]: no function or associated item named `from_xml` found for struct `SRX` in the current scope
--> src/main.rs:5:20
|
5 | let srx = SRX::from_xml(&fs::read_to_string("data/language_tools.segment.srx").unwrap())?;
| ^^^^^^^^ function or associated item not found in `SRX`
error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `Try`)
--> src/main.rs:5:15
|
4 | / fn main() {
5 | | let srx = SRX::from_xml(&fs::read_to_string("data/language_tools.segment.srx").unwrap())?;
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot use the `?` operator in a function that returns `()`
6 | | let english_rules = srx.language_rules("en");
7 | |
... |
12 | | );
13 | | }
| |_- this function should return `Result` or `Option` to accept `?`
|
= help: the trait `Try` is not implemented for `()`
= note: required by `from_error`
error: aborting due to 2 previous errors
[package]
name = "rsegment"
version = "0.1.0"
edition = "2018"
[dependencies]
srx = { version = "0.1.3", features = ["from_xml"] }
Sorry, I meant from_str
use std::{fs, str::FromStr};
was missing, my fault.