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

Get access to Path components #76

Open
kamilglod opened this issue Oct 30, 2023 · 4 comments
Open

Get access to Path components #76

kamilglod opened this issue Oct 30, 2023 · 4 comments

Comments

@kamilglod
Copy link

I'm trying to use Path to build field path like ["top_level", "0", "nested_field1"], it would be easy when having access to Path.components but it's private. Can you add a possibility to access path in a different way than .to_string()? All that needs to be done is to make __iter() public.

@jprochazk
Copy link
Owner

Please post a code example which shows what you're trying to do. How does __iter help you build a path?

@kamilglod
Copy link
Author

@jprochazk
Let's say I have struct like:

pub struct ValidationError {
    pub field: Vec<String>,
    pub code: String,
}

where field is a filed like ["top_level", "0", "nested_field1"]
And I want to return vec of those ValudationError's:

pub fn aggregate_errors(validation_errors: &Report) -> Vec<ValidationError> {
    let mut flatten_errors: Vec<ValidationError> = Vec::new();

    for (path, error) in validation_errors.iter() {
        let field = Vec::from_iter(path.__iter().rev().map(|(_kind, val)| val.to_string()));
        flatten_errors.push(ValidationError {
            code: error.message().to_string(),
            field,
        });
    }

    flatten_errors
}

@jprochazk
Copy link
Owner

Report is pretty much the same thing as a Vec<ValidationError>. What is ValidationError used for?

@kamilglod
Copy link
Author

It's used to pass it as dict to Python code.

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

2 participants