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

str_to_term in serde code doesn't fall back to string #640

Open
benhaney opened this issue Jul 14, 2024 · 0 comments
Open

str_to_term in serde code doesn't fall back to string #640

benhaney opened this issue Jul 14, 2024 · 0 comments

Comments

@benhaney
Copy link
Contributor

Quick drive-by issue just to note that this function doesn't behave like its comment says it does:

/**
* Attempts to create an atom term from the provided string (if the atom already exists in the atom table). If not, returns a string term.
*/
pub fn str_to_term<'a>(env: &Env<'a>, string: &str) -> Result<Term<'a>, Error> {
if string == "Ok" {
Ok(ok().encode(*env))
} else if string == "Err" {
Ok(error().encode(*env))
} else {
match Atom::try_from_bytes(*env, string.as_bytes()) {
Ok(Some(term)) => Ok(term.encode(*env)),
Ok(None) => Err(Error::InvalidStringable),
_ => Err(Error::InvalidStringable),
}
}
}

Specifically, it says it returns a string term if there isn't already an existing atom:

* Attempts to create an atom term from the provided string (if the atom already exists in the atom table). If not, returns a string term.

but then doesn't do that and just returns an error instead:

Ok(None) => Err(Error::InvalidStringable),

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