Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

from_xml not found #6

Closed
ZJaume opened this issue Apr 11, 2022 · 2 comments
Closed

from_xml not found #6

ZJaume opened this issue Apr 11, 2022 · 2 comments

Comments

@ZJaume
Copy link
Contributor

ZJaume commented Apr 11, 2022

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"] }
@ZJaume
Copy link
Contributor Author

ZJaume commented Apr 11, 2022

Sorry, I meant from_str

@ZJaume
Copy link
Contributor Author

ZJaume commented Apr 11, 2022

use std::{fs, str::FromStr}; was missing, my fault.

@ZJaume ZJaume closed this as completed Apr 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant